I have purchased a ticket from Kings Cross London to Waverly Edinburgh. The apartment I have rented is closer to Haymarket Edinburgh. Must I exit the train at Waverly or may I exit train at Haymarket?
If you have bought ticket all the way to Waverly nobody can stop you from getting off the train anywhere before Waverly so the answer is you may exit the train in Haymarket.
The Haymarket stop comes after Waverly, when northbound. I don't know the official answer, but the two destinations cost the same price, so I'd try staying onboard, if your specific departure is a train that does continue beyond Waverly station.
Haymarket is indeed beyond Waverly station. I would inquire in Kings Cross if your ticket specifically states that you travel to Waverly. If it costs the same it should not be problem. If not you can buy additional ticket from Waverly to Haymarket in London.
as laura says , just stay on board if your train goes further then Edinburgh, it is only 2 or 3 minutes further but only if it is not terminating in Edinburgh