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制"
「買單」源自「埋單」
上文提到「買單」,原為粵方言詞,寫作「埋單」。「埋」是收攏、靠攏的意思,埋單就是把消費的帳單收攏在一起最後結帳。粵語的「埋單」和普通話的「買單」讀音相合:「埋」(mai),粵語是個低平調(陽平),一般認為調值是21;「買」(mai),普通話單唸是個降升調,但在「買單」一詞中,則讀作半三聲,調值211,與粵語的低平調非常脗合。因此,「埋單」進入普通話後,多寫作「買單」。可以說,普通話的「買單」,借用了粵語的音,然後另起爐灶,造了「買單」這個新詞。
"買單" 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 "買單".