We've already crossed the Rubicon on this, and countries will justify infringing the rights of millions if a policy has a potential of saving millions more. Fortunately I can't think of a situation where a contagious human virus would be the only or the best way to save millions, but governments have no trouble making the ethically-questionable decision that some groups of people should die through lockdowns in order that other (generally older) groups of people should survive.
> mandates it for foreign travellers in transit who got stuck in your country? mandates for the foreign diplomatic staff?
A government could announce the policy well in advance, to give people a chance to leave, although the distinction between at home and abroad is moot if the contagion can spread outside the country, which of course it will. Again, sadly, there are plenty of countries that take the view that citizens of other countries have effectively no moral weight and the government has no duty to protect their rights.