The moral justification is very simple - the people of Thailand (I hope the Thai people will pardon me from using them as an example, going on from the parent post ) get to make the rules of what happens in Thailand (e.g. they have sovereignty) and you don't. There can be international agreements where countries agree to give up part of sovereignty and agree to be limit their actions, but the default situation is that they literally get to make up laws in their borders, and existing in their borders means that you'll be held to these laws, by force if necessary, no matter if you agree or not.
They don't have to let you across the border if they don't want to, and they don't need a justification to do so - that is their inherent right. If they want to let anyone in, no questions asked, that is their right too. And if they choose to allow some people under some conditions - same thing. You're not part of their social contract, whatever that is, and you have no right to be treated equally unless they choose to - they can and will have preferential treatment for themselves.
From your comment "Or did you perhaps unwittingly sign a new one with Thailand, by entering their territory?" is probably the closest one to truth, but it's not unwittingly - the tourist visa explicitly has a number of terms and conditions; and you either intentionally accept them or don't get the visa. With this visa, they are offering a very particular social contract for you, and it's up to you to take it or leave it.