Due to a medical issue I can't sleep well with tight trousers and wearing a belt. Should I expect any problems if I go to the toilet, put my pyjamas on, go to sleep in my seat and then change back after I wake up and before landing.
Given that some airlines even give you a complimentary pyjama when flying in first class I'd say that it would be perfectly legal for you to wear one on the plane regardless of which class you're flying in. Worst case scenario you'll get some looks from other passengers. Go ahead and fly comfortable.
Unless you're concerned about your appearance prior to boarding the flight for some reason, I see no reason not to take @cgcampbell's advice.
I have to wear a metallic brace for an arthritic knee, so I either wear comfortable shorts, or a pair of (equally comfortable) zip-off pants so I can easily show the brace to security agents (TSA here in the US). I still get wanded at each security point, but I've only had one agent in Cambodia insist that I take the brace off, but I was able to convince her that it was very inconvenient to do so, so she backed off. This was on a trip with six international flights just recently.
If you're not concerned about your prior appearance or your post flight appearance (you're not being picked up by clients or someone else who expects you to be dressed well), then wear comfortable clothes for the the entire flight.
If you are concerned about your post flight appearance, every airport in the world that I've flown into has large enough restrooms in their arrival halls to easily change into appropriate clothes after you've gotten off your flight and before anyone who matters can see you.
as someone who only wears sweatpants/sweatshirts on planes, nobody will question it. I show up in them, but changing in the bathroom shouldn't cause an issue as long as you can stuff your other clothes into your carry-on. Just make sure, as @Joe Blow said, your pajamas don't let anything illegal out.
I fly about 100,000 miles a year, mostly long haul. I wear them all the time, in economy and business class.
It's fine and your fellow passengers won't think twice about it. Just make sure you're wearing undergarments of some kind so people can't see the outline of your genitals. If you're really concerned about it, buy some nicer ones that toe the line between casual and straight up PJs.
I would actually suggest changing in the airport, not on the plane. Handicap stalls are much larger and have places to put your luggage. Wear flip flops, and stand on them and a seat protector.
Also, airplanes tend to be cold at altitude. You may want to bring some wooly socks.
I have been travelling internationally a lot. I have travelled in shorts all the way to a three piece suite, and never had any issue. My preferred option is always:
Find a CLEAN restroom and change into comfortable clothes before boarding. Alternatively you can change right after boarding. If you wait too long, the restroom floor starts getting dirty, and there's a chance you might get stuff that you don't want on your clothes, especially on your pant leg bottoms.
If you are going to a decent airport, you can change after exiting immigration, again in a clean restroom.
If the airport is not-so-good, you have to either change in the plane restroom or take your chances with airport restrooms.
My 2 cents. Hope this helps.