Villagers will try to pathfind through solid walls in order to reach their POI blocks, resulting in them being stuck until their schedule allows them to switch to a different POI. This problem tends to plague custom villages with large structures. I've screenshotted an example village and diagrammed it below. This can be reproduced by creating a large chambered building with job sites and beds with a single or double door entrance and then spawning villagers.
MC-156031 can also be observed with this layout,
Linked issues
duplicates
Attachments
Comments
I suspect the path is too long in this case, so the closest position to the workstation the villager manages to path to is behind the wall then.
This is a duplicate of MC-160582

Please use the search function in the future to prevent duplicate reports.
Quick Links:
📓 Issue Guidelines – 💬 Community Support – 📧 Customer Support – ✍️ Feedback and Suggestions – 📖 Game Wiki
"I suspect the path is too long in this case, so the closest position to the workstation the villager manages to path to is behind the wall then.:
I don't think this is the case since the farmers(the villagers that had the furthest travel travel distance.) had no trouble navigating to their work sites. However, this is indeed a duplicate of MC-160582. That bug didn't show when searched this problem up.
To long of a path? 4 blocks?
Duplicate of MC-142817