It might be helpful if you posted the grid reference of the farmyard.
I can think of plenty of farmyards with tracks through them in the Scotland Borders where I have walked recently (and guidebooks also have routes through) where there are no access issues in following the track through the farm yard. Some other farms wish to redirect people around the outside of the farm and indicate a path which should be followed and this is entirely reasonable. Of course you could always politely enquire at the farm.
The Scottish Outdoor Access Code is very worthwhile reading if you want to understand the rules and their interpretation. It
states:
Access through farmyards and other buildings and associated land 3.40 Access rights do not extend to farmyards. Farmyards are often busy places and so health and safety may be a particular issue. Many farmers also have concerns about security and privacy. However, traditionally, access to the countryside is often taken through farmyards. Using paths and tracks will often be the best means of access and will help the land manager. Accordingly, farmers are encouraged to continue to allow people to go through farmyards where this would not interfere unreasonably with land management requirements or privacy.
3.41 If you are following a path or track which goes through a farmyard, the guidance is as follows:
• if the route is a right of way or a core path, then you can follow this through the farmyard at any time;
• if a reasonable, passable alternative route is signposted around the farmyard and buildings, then follow this. In the absence of a right of way, core path or a reasonable, signposted route around the farmyard and buildings, you:
• might be able to go through the farmyard if the farmer is content or if access has been taken on a customary basis in the past;
• could exercise your access rights to go around the farmyard and buildings. If you do go through a farmyard, proceed safely and carefully, watch out for moving vehicles and livestock, and respect the privacy of people living on the farm.
In practice, exercising access rights responsibly is about making informed decisions about what it is reasonable to do in everyday situations using common sense.
Lots of examples are given.