i made a couple of deals in all the RPG servers and they usually go something about this way.
to start with according to server rules yes they are legal as long as the deal is made with game currency.
and about the safety well, one of the sides always has to compromise, if u buying acc either u pay first and risk losing the money or the guy gives u the acc first and risk loosing the char.
i advise u to make all the deal talking in game, so if anything goes wrong admins can check the logs if they decide to try to solve the case, also take prints of every chat and every trade.
in all deals i made both selling and buying it worked pretty much like guy with char gives char for persons to log and see, if everything is ok and fit the deal the char owner gives either email or the code to change email, and after the seller gets the payment agreed on.
as i said before. always one of the sides has to risk it. Just in case try to scout out the persons who u dealing with, like forum acc for instance, if its a person with like 500 posts and old member and with lot of similar deals before, its less likely he/she will try to fuk you up then some guy with new acc with 2 or 3 posts who just showed up yesterday.
Tho i dont think theres 100 % safe way of doing this.
well, i supose u could try to ask someone to be like the middle man, someone known and trusted like one of forum mods or something, if they have the time maybe they dont mind of doing it, altho i wouldnt if i was them cus i believe if they do it once, they will never do anything else besides that on their life xD