I think you'll find Bruce's answer, as usual, is the closest to the truth. Be wary of taking a rebate from a Realtor that is not disclosed to your lender. Some lenders prohibit this. Ask your Realtor and your loan officer about such arrangements before having your closing delayed or having problems afterwards.
When a seller lists a house, he agrees with the listing Realtor how much he will pay both to the listing Realtor and a Realtor who brings a buyer (actually the brokerage companies the Realtors work for). From the seller's point of view the money he receives is less than than the listing price not only by other closing costs but by those commission payments also.
As pointed out, since all of the money comes from either the buyer, the buyer's lender or is paid on the buyer's behalf by a third party, the money that you, the buyer, pay includes commissions plus closing costs plus money received by the seller. I hesitate to call paying indirectly "free" but it's not more than usual, and doesn't affect the sale, normally. "Normally" includes builders. If you go to a builder with a Realtor, you pay the same price as without, but sometimes the Realtor can negotiate more effectively for you. In this case, you might actually consider it free or to your benefit (not to mention the advice and experience you get).
HUD is no different from any other seller. They set a price and expect to pay some costs for closing and commissions. They won't allow more than 5% of sale price nor less than $500 as commission to your Realtor. They also pay the listing broker (BLB) from the proceeds 0.5 to 1% roughly. HUD will also pay additional closing costs up to 3% of the sale price, but as pointed out, these costs are considered as reductions in the net amount received by HUD.
Since the BLB gets the same amount no matter who buys, only the closing costs and your Realtor's commissions matter in reducing the net proceeds. HUD will use their rules to decide which bid gets the property but basically best net proceeds wins. (There is a pecking order, not necessarily what you expect, as to which class of bidder will win.) So, higher commissions can put you at a disadvantage compared to other bidders, potentially.
After the closing, a check from the title company is sent to the Realtor's broker for the commission. Another check is sent to the BLB for their commission. The buyer does not pay anyone directly except the title company and other service providers who inspect, appraise or perform services for the buyer. The buyer does not pay the Realtor directly ever, and does not pay his broker, unless specifically agreed in writing beforehand. The commission from HUD (the seller) via the title company is the accepted means for the Realtor of the buyer to be paid.
Does that help clarify who pays the commission?