Yes, you have “the right to leave”. Of course, you do. If they forcibly restrain you on the premises, that’s kidnapping.
Look, not every day you come into work is a negotiation. They need you there at such-and-such time and for so long. If you cannot perform that duty, then they can fire you in order to free up the position to hire someone else who will be there.
You can feel good about setting proper expectations up front – and it’s not your fault then if they try to take advantage of you – but even so, that’s just feelings, not work and not getting paid.
Getting fired from the job isn’t necessarily about them being mean to you… or hating you… or otherwise disrespecting you (although, it could be if the boss really is a jerk). Sometimes, they just need a better fitting person. And if so, then you need a job that fits you better, too.
If you’re having problems keeping to the schedule you need, then look at these symptoms as indicators you should polish up the ole’ resumé and find a different job.