In short, 買單 comes from 埋單 because Cantonese 埋 (tone 4, 陽平, contour 21 or 11) sounds very similar to Mandarin 買 (tone 3, 上聲, contour 214) where the ending rise isn't sounded when followed by 單.
Here Cantonese 埋 means to "settle", "finish off", or "draw near". E.g. 埋數 (finish off the numbers / do accounting), 埋位 (settle in to a seat), 埋口 (heal up an open wound).
The below are from references in Wikipedia 埋單, mentioned by @水巷孑蠻. Translations mine.
Lau Tin Chi (劉天賜)
Wen Wei Po 2003-02-08, "俗語趣談：埋單" (archived version)
Explanation: to pay a bill, to settle a bill [or score]; also popularly interpreted as [causing] death, finishing off. Nowadays in Mainland, Taiwan, etc., being gradually influenced by Hong Kong language [usage], "埋單" is also used to express paying of a bill. But the wrong word is used, it is thought to be "買單", and hardly known that "埋" is quintessence of Cantonese.
Dr Lam Kin Ping (林建平博士)
Archived version of CUHK 普通話速遞 No. 48, "衣食住行AA制"
"買單" sourced from "埋單"
"買單" mentioned in the text above is originally a Cantonese phrase, written "埋單". "埋" has the meaning of gathering, drawing close; 埋單 is to gather in the bills of expenses together for a final paying of the bill. Cantonese "埋單" and Mandarin "買單" have matching pronunciations: "埋" (mai) in Cantonese has lower level tone (light level) [i.e. tone 4], commonly held to have tone value 21; "買" (mai) read alone in Mandarin has falling-rising tone, but in the phrase "買單", is read in half-third-tone, tone value 211, quite a match with Cantonese lower level tone. Thus, "埋單" after entering Mandarin [usage], is mostly written "買單". One may say, Mandarin's "買單" has borrowed the pronunciation in Cantonese, then set up its own shop, creating the new phrase "買單".