Realtors tend to have a lot of contacts. The realtor I worked with knew “a great guy” for every aspect of the house (roof, plumbing, cabinets, driveways, etc.) due to the fact that she naturally encountered so many of these tradespeople.
She would get recommendations from sellers. Either the seller recently had work done in order to improve the home before putting it on the market, or, the seller had some trusted expert they used for years.
My realtor actually encouraged me to ask her for any contacts if I needed something done in the future. I sense that her contacts like having customer referrals as well.