All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Phones are among the bounties of Allah on the people, so whoever uses them in goodness, then he has fulfilled gratitude for having them, and whoever uses them in evil, is subsequently ungrateful (to Allah) for providing them.
Among the acts of ungratefulness for this blessing is what you have mentioned in this question, which is the illicit relations between non-Mahrams. Their imagination of committing Zina (fornication or adultery) is an evil thing: the Zina of the heart is done by wishing.
Abu Hurayrah narrated that the Prophet said: “The son of Aadam will have his share of Zina no matter how well he/she endeavors to avoid it. The Zina of the eyes is by gazing, the Zina of the ears is by listening, the Zina of the tongue is by talking, the Zina of the hands is by touching, the Zina of the foot is by walking [to forbidden places], and the heart desires and wishes. Then, the private parts either submit to this or deny it.” [Muslim].
It [i.e. wishing by the heart] entails incurring a sin. However, it is not the real Zina that necessitates Hadd (i.e. the corporal punishment determined by the Islamic Law); rather, it is a means that leads to it.
This action cannot be a protection from Zina; rather, it is a motive that leads to it as it arouses one’s lust and it does not suppress it. The protection is indeed by fearing Allah, avoiding this act completely, and taking the initiative to marry or to fast when one is unable to marry. Additionally, one should preoccupy him/herself by acquiring useful knowledge and performing righteous deeds and by keeping company with pious people.
There is no effect of this act, or what things it may lead to, like masturbation, on the matter marriage, and does not make marriage prohibited. Thus, it is permissible to marry the mother of this girl or her daughter, for example.
Allah knows best.