Lyngarr's Wandering Pets is a simple mod that lets your tamed pets roam freely within a defined area. Just sneak + right-click on your pet to toggle between Wandering and Following mode.
As of 2.1.0, you can change which pets are able to wander via the wanderable_mobs field in the lyngarrwanderingpets.properties file in the config folder.
The default value is wanderable_mobs=minecraft:parrot,minecraft:cat,minecraft:wolf. You can safely remove any pet from the default ones, but adding any will most likely break things, do so at your own risk.
This mod is server-side, meaning you can install it on a server without requiring players to have Fabric or any additional mods. It also works perfectly in singleplayer.