Coupons pay in lumps but interest accrues daily. If you buy a bond three months into a six-month coupon period, the seller has earned half that coupon and you must reimburse them. The bond exchanges at the quoted clean-price plus accrued, which together are the dirty-price.
This is not a cost. You get it back in full at the next coupon date, when you receive the whole payment despite having held for only part of the period. It just shifts cash around.
Example: a $100,000 face bond with a 5% coupon pays $2,500 every six months. You buy it 90 days into a 181-day period on an actual/actual basis. Accrued interest is $2,500 x 90 / 181 = $1,243.09, which you add to the invoice.
Related: clean-price, dirty-price, coupon, day-count-convention