Likely everyone's parents.
Like a lot of advice you get from your friends and family, there is no reason "own it for at least 5 years" beside it's a nice round number, and not obviously bad advice.
Dave Ramsey says 2-3 years, which is much easier to back up. I'm going to make a couple of assumptions that most people assume about the housing market.
1) You will always be able to sell your home for what you paid for it.
2) Even with repairs, taxes, insurance, and other new costs, you'll pay about the same as renting a similar place.
You'll pay about 6% commission every time you sell. Let's say you buy a 200k home (200000 * .06 = 12000). Let's also assume appreciation at 3% a year.
So you've got to divide the commission by the months you lived there to determine if it was worthwhile.
after 1 year => 12000 / 12 months = $1000 a month (home worth 203k)
after 2 year => 12000 / 24 months = $500 a month (home worth 207k)
after 3 year => 12000 / 36 months = $333 a month (home worth 213k)
after 4 year => 12000 / 48 months = $250 a month (home worth 220k)
after 5 year => 12000 / 60 months = $200 a month (home worth 226k)
Assuming rent of $1000, at one year there is no advantage.
At 2 years, you see some decent returns, but a major expense like HVAC replacement could wipe this out pretty fast.
At 3 years, the value has appreciated enough to cover the commission, so this is the break-even point.
4+ Years you're turning a profit on paper on your house.
So how did 5 years become conventional wisdom
In this example, 3 years is the break-even point, but I made a lot of assumptions. You may have to replace an HVAC, or have another costly repair which means you'd have to hold it longer. Your house may not appreciate if there is an economic slowdown.
Owning a house is much different than renting one. If you get a great new job somewhere else, sublet the place and move. With a house, you'll have to put it on the market and wait for another buyer.
EDIT: About the assumptions (and stuff I left out).
I left out loan origination and amortization schedules because the 5-year number likely came from people making the same assumptions I stated and running the numbers.
The people who gave you this advice don't know the loan origination costs or the amortization schedule. This answer focused on how 5 years became the rule of thumb. I believe people converged on this number because
1) It gives them enough time to absorb one-time origination costs and commissions. People usually buy another home after selling one, so they'll need enough money to cover the 6% commission.
2) Even in this VERY optimistic scenario, it takes 3 years to break even. Things will probably not go quite this well. 5 years makes this slightly more realistic.
Worth remembering - there are people who bought in 2008 who's property value has still not recovered. Once you know the exact cost and run these numbers yourself and make sure you've looked at a less optimistic appriciation rate.