The story
From use of X/x to mean “kiss” and O/o to mean “hug”. Use of “X” to indicate a kiss attested since 1763, preceded by medieval use of an “X”, which was then kissed by illiterates to indicate a signature. Use of “O” is more recent, and presumably created by analogy (e.g., X/O in tic-tac-toe). Speculative theories on precise origins abound, including folk etymologies.
Etymology from Wiktionary, CC BY-SA 4.0.