It is impossible to create a cheaper and more effective health care system purely through private markets and the GOP knows this. The only way to cut costs otherwise is to slash tons of benefits and make everything literally worse. Because of this the two GOP factions in the House (where representatives are elected to represent congressional districts, which can be reshaped to capture a specific voting bloc and ensure constant easy reelection for radicals) - the "moderate" Republicans and the fanatically small government Freedom Caucus could not see eye to eye, and the Senate, which cannot be gerrymandered since senators represent entire states, was not keen on the House's ideas since it would mean tough reelection campaigns for senators. So it was assumed that internal dynamics would produce a never-ending stalemate, and initially that seemed true.
But the GOP has gotten to the point that they are afraid they'll be primaried for not doing ANYTHING since usually only the most rabid party followers show up during the primaries. They're willing to gamble that even though the public hates this bill, politics are so polarized that theyll be able to win reelection anyway.