"spent a lot of money to buy a house" vs. "spent a lot of money buying a house"
Spending a lot of money "to buy" a house would be taken the same as spending a lot of money on/for a house, meaning that the price was high. (Of course, few people buy a house outright; they take out a mortgage and pay it off bit by bit, paying much more, over the years, than the price; however, one still speaks of the price as "how much you pay" for the house.)
But paying a lot "buying" a house can refer to paying a lot WHILE buying the house. This means the down payment, plus all closing costs, which are the additional up-front expenses incident to the purchase transaction. Closing costs can include many types of fees (legal, registration, title search, appraisal, termite inspection, earthquake report, to name a few), plus "points" if applied. In some times and places, these costs could run several thousand dollars—a big deal