How would you differentiate between Ayşe being the one visited and someone else being visited?
hmm if it were other way around, we would have said "Ayşe dedi ki, o seni ziyaret etmiş". (Ayşe said that she visited you)
let me rephrase my question. how would you say "Ayşe said that you visited him" as if talking about another (third) person?
same as above - you cannot differentiate. It is usually apparent from the context. If not, you wouldn't say "onu" and you would rather use a name. (Ayşe dedi ki sen davtul'u ziyaret etmişsin)
Good point. Actually it could be understood from the context. If Ayşe was the one visited, the sentence might be like 'Ayşe dedi ki sen kendisini ziyaret etmişsin' and it would be certain that Ayşe is the one who is visited. However in the sentence above, you cannot differentiate it apart from the context
"Ayse said you visited it" was marked wrong. Is that an oversight, or does ziyaret etmek have to refer to a person?
Actually, this sentence form is borrowed from Persian along with "ki" itself. "ki" in Persian is the equivalent of French "qui" and English "who". Actually here "ki" stands for "that" in English. "Ayşe dedi ki = Ayşe said that". This form is colloquial and easy to understand for new beginners especially for Indo-european natives. That is why a good point to start. A pure turkish form for that sentence (which is preferred written language) is actually: "Ayşe onu ziyaret ettiğini söyledi".
I'm a little bit confused about the use of ki here, can someone explain why we should use it in this sentence?
I think "ki" is used here as conjugation and means "that" Read the tips and notes. There it is explained.