Do fruit trees planted in a greenhouse in Stardew Valley gain quality?
They do gain quality. From the wiki (emphasis mine):
A tree's fruit increases in quality by one star per year of tree age after reaching maturity
A tree needs to grow to maturity which takes 28 days, and then needs to be mature for a year before the fruit quality increases. This means you need to wait until 15/16 Summer for your trees to gain quality if you planted them on 15 Spring.
I have seen the trees in my greenhouse giving silver quality fruit after that period, so there's no exception for trees in the greenhouse to this rule.