Spain's top military chief has resigned after it was revealed he and other senior officers jumped the queue for a coronavirus vaccine.