It was always a purely financial decision. If they sold a lot of guns, they kept them. If a particular store didn't sell a lot, they used the space for something else. It is all about money.
It was a little more in depth than that, I was still working AP/LP for them when a lot of this came down the pipes. It was Risk vs Reward most stores did not hire the most competent people to sell guns, further that with lack of education from ground level through management and lack of staying in compliance with State and Federal Regulations. It was deemed if a store did not make X amount on Firearms Sales it was not worth the risk of getting popped for violations and having to pay fines and or surrender the FFL. So they stopped selling in most of the Metroplex stores although it really never affected More rural Stores
I remember Wally World selling handguns way back in the day.
Again driving factor of Risk vs Reward handguns mean more compliance and regulations to keep up with, the Fact that a Waco Area Store sold a Glock 19 to David Keresh and completely fubared the 4473 did not help for the argument to keep them.