The long and the short of it is that a constitutional monarch should not express political views, especially not if they can be considered to favour party politics.
I would have thought that King Charles or any other royal person could attend COP 27 as long as he did not speak at the meeting or comment upon speeches made there.
As it is apparently being held in Egypt, there are other matters of protocol to take into consideration than whether the King's attendence could be construed as expressing a political opinion. Usually, the visit of a head of state to another country comes about after lengthy diplomatic discussions and I am not clear as to whether a king, has like the rest of us, to wait until he is invited, or whether he can still express the desire to visit a country and then automatically receive an invitation.
I do know that private citizens do not as a matter of etiquette invite royalty. Royalty signify that they would like to visit one, whereupon if any of you should ever receive such a notification, (I certainly don't expect to) you reply that you are greatly honoured and the occasion suggested suits you fine (whether it does or not.)
If indeed Liz Truss was so lacking in manners as to TELL the king anything, I hope he, or a palace official told her nicely that the Prime Minister may ADVISE the sovereign, but not TELL him what he may or may not do.