What relation does harmony have to repetition?
A rather tenuous one, I think!
As I understand, harmony in music can be achieved either through melody / chord — when the frequencies of the sounds are in phase sync
Hmmm... that's not 'wrong' exactly... - consonance in music occurs when we put together sounds with simple ratios between their frequencies. You could see this as a kind of phase correspondence, but actually, as mentioned in my answer to this question, when 'looking for' harmony, the ear doesn't listen for phase relationships in the time domain, but pitch relationships in the frequency domain. And it is able to find consonances even when there isn't an exact 'phase lock'. So I don't personally find this the most helpful way to think about it.
or through the rhythmicality (the same rhythmical pattern that repeats itself).
In English, the word 'rhythm' refers to something like a drum beat that repeats over a much longer period than an audio waveform. Our auditory system processes this in a different way, so we don't call this 'harmony'.
Can we say in this case that harmony is when things repeat themselves, at least from the mathematical perspective?
The human ear is cleverer than just looking for repetition - it can do a frequency analysis of a waveform with very little repetition, and find bands of energy that have something close to simple ratio relationships with those in another waveform that itself has very little repetition. Or to put it another way, the ear can find 'harmony' in some really messy collections of sounds, because it can find pitch in very messy waveforms. Here's an example of a single pitched wave that the ear can definitely get a sense of pitch out of - It's brass_acoustic_006-032-075.wav from nsynth-test at https://magenta.tensorflow.org/datasets/nsynth.
This is only the start of the note - it settles down and looks a little more periodic later. And yet even from this messy bit of note (a tenth of a second or so), the ear can pick out a definite sense of pitch, which could have a harmonic relationship with other waves.
But - can you see any repeating pattern in the wave? Maybe you kind of can, but it's very unclear. This goes back to what I said before - the ear works in a cleverer way than just looking for obvious repeating patterns. Then again, you could just say that it's very good at finding repeating patterns at levels that aren't immediately obvious.- It really comes down to the fact that you can look at audio from a time or frequency domain (again, as mentioned in the question What causes consonance in music?).