Not much definitive info is found on the web about specific bed linking for villagers. Here and there are some references to 16 blocks horizontal and 4 blocks vertical. This test map shows that is not quite correct.
That vertical distance is correct of 4 blocks vetical, combining above and below is a total of 8, including the lavel of the bed.
The horizontal distance is not quite accurate and the reasoning on it was very difficult to ascertain. The horizontal block distance from a bed's pillow is indeed 16, but only on the north and west directions. It is 17 when measuing from the same spot and going east or south.
The best way to explain why it is this is from a notation about raid triggering:
"A player with bad omen triggers a raid when their position (i.e. eyes) enters a village's AABB. However, the game rounds a player's position down to the nearest integer before checking if the player is inside the village's AABB. Additionally, due to a logic error, a position on the edge of the AABB is considered inside the AABB regardless of which edge it is. As a consequence a player within 1 block to the south, east, or top of the AABB can trigger a raid before the player physically enters the village's AABB. This is why using bad omen to measure a village's AABB is only accurate for the north, west, and bottom edges of the AABB."
(emphasis by me of similar terms and logic to villager bed linking)
This is the closest documentation that comes close to explaining why a villager 17 blocks east or 17 blocks south can link to a bed when in controlled conditions.
The map provided is a void world where an example bed is set up and measuring out from the bed the bounding box of how far away a villager can link to a bed. Load this up and experiment with it to see for yourself where villagers can link and where they cannot.

