Some frame challenges
More like "you need the following conditions to have the scenario you describe", not the "this is impossible" challenges.
There were no affordable locks in medieval times; they were absolute luxury contraptions. They were typically used on the treasure chests of the wealthy and/or powerful.
Even iron wasn't exactly cheap. You don't have prison cells with iron bars and a locked door, that came only with the industrial revolution when forging became mechanised, which started with watermills driving drop hammers - this became reasonably common in Renaissance times, which is usually considered to be after medieval times.
Even then, it is much cheaper to build the prison as a room with a hole in the ceiling. Nothing goes in or out except dangling from a rope that is held by as many sturdy men as necessary for whatever the weight is: prisoners, food, waste. Has the nice side effect that nothing goes in or out except in the presence of guards.
Personnel is cheap
Or, rather, mechanisms are expensive.
In medieval times, payment for a maid could be food, housing, and two dresses per year, and given that food and housing couldn't be taken for granted and fabric for dresses was pretty expensive, this could be a pretty fair deal.
Guards were even more expensive: Their gear contained metal where leather and wood wouldn't do.
So... again we use the hole-in-the-ceiling prison. The prison personnel is much cheaper than a grille door with a - gasp! - lock.
So we must be in a gilded-cage scenario
Maybe the princess is on display, for political reasons.
Or maybe her captor is just mocking her: See, I consider you so weak that you won't escape even from an unsafe prison.
Or she's the kind of prisoner that you can take hostage to keep somebody from rebelling, but that person would surely rebel if you put her into a standard hole-in-the-ceiling prison because such prisons take away first health, then life - you can't really clean them.
However, there's still the question: Why locks? Keeping doors and windows guarded at all times is still much cheaper than a lock.
So... the captor shows off his wealth.
"Look, I can afford to put her in a locked room WITH NO GUARDS."
(Such an approach to guarding an important prisoner would be considered a bad idea, and indeed the story will progress in her escaping... guards would have prevented that.)
You don't put a lock on a window
It's just too expensive.
Medieval windows didn't have glass, they had shutters to keep bad weather out.
Improved windows had a grill, to keep attackers out (or prisoners in). The grill would be set into the stone, no lock.
Expensive windows had oiled parchment. It's not transparent, but it's translucent so you get light into the room.
A possible scenario
It's not the window.
It's part of a mind game: The Evil Overlord is taunting the princess.
Yes, it's an expensive grill door. With an absurdly expensive trick lock.
And the key hanging from a hook... just out of reach.
The shoddy worksmanship could be anywhere:
- The window has bars, these were replaced because "rusty does not befit a princess", but the replacement stones that the bars are set into were sandstone.
- The hook is nailed to a wooden piece of furniture. The hook was replaced, and the new nails were slightly less thick than the previous ones. Or maybe the hook has been replaced so many times that the wood became brittle and any nail could be pulled out by hand.
The jailers know this, but fixing this would cost money (if only to pay a carpenter to do the job properly), so nothing was done, and somehow the princess manages to attach a rope to the hook and pulls it out.
Another scenario (just shoddy, not elaborate locks though)
Not a lock.
Just a rivet closing a neck ring or manacles. The rivet is a pretty soft metal so you can file it open with little effort, but files are something that only smiths own so it's practically inescapable. (I read that thralls in ye olde times in England had "thrall rings" around their necks that made their status visible; that was fictional work though, so I don't know much about how much, if any, this was in practice.)
Anyway: No file near the princess, problem solved.
Except maybe the smith wasn't competent. Or sabotaging the work.
Or the smith couldn't be bothered with doing so low-level work, and sent the apprentice.
Either way, the rivet was fastened just enough to barely hold, and can be moved out by hand given oil.
Probably not an answer to the question, but I kinda like the idea of an apprentice mucking up a perfectly reasonable and simple job, just because the master didn't have the time to properly deal with the task.