What right does a Captain or the state have to prevent a passenger leaving an aircraft which is on the ramp??
None whatsoever would be me answer.
(I guess a state could in theory order a person to remain onboard on the basis that they are being refused entry to the country.)