Because productive farms require lots of expensive maintenance/equipment. A vertical farm lets you optimize for that use case since its the only use of the infrastructure and you can align everything towards maximum use of those scarce resources.
Random roofs don't optimize for that usage pattern, and so you need to use them in an application where the primary cost is the install cost rather than an upkeep cost. Solar panels are a perfect fit. Farms are a terrible fit.