Actually, what you're using as an argument here as a reason that "it can't be true" isn't relevant to that at all. And therefore cannot be used as an argument to prove true or false the claim that "if you have sex with someone you are marrying them according to scripture".
John 4:17 Jesus is saying essentially, because you're not with your original husband, the one you're currently with is not your husband. Therefore she speaks true to say "I have no husband". It DOESN'T mean that sex didn't consummate her original, legal marriage. Or that sex couldn't be the act to make marriage official. Just to note I'm not speculating on that as being true or false, I haven't considered the topic enough to draw a conclusion.
Are two wed if they do not consummate? So one can argue here that consummation is only legitimate in a couples first marriage, and other legal marriages. Like in the case she was widowed and re-married. Otherwise if a woman was divorced, she was to remain single, or reconcile to her original husband. One could also speculate with potential accuracy to say it's possible the 5 husbands that are referred to here are all illegitimate, and there's a sixth unmentioned husband which was her legitimate husband. Why? Because Jesus does recognize '5 husbands' in a social/worldy sense, but also saying she's not currently wed/with a husband, and surely that's the latest one of the five.
Commentary from biblehub below confirms my understanding here. You can read the full commentary from the site, the complete of both were a little too much I felt to paste here.
https://biblehub.com/john/4-17.htm
Pulpit Commentary
Verses 17, 18. - The woman answered, and said to him, I have no husband. Jesus saith unto her, Thou said correctly, Husband have I none: for thou hast had five husbands; and he whom thou now hast is not thy husband. This true thing hast thou spoken. The woman resists the description which Jesus assumes that she bears to the man with whom she stands in illegal relations. Convinced, brought to bay, she cannot lie to Jesus. She says, in penitence and shame, "I have no husband." There is no concealment of the fact; she must need the cleansing of the life-giving stream. Jesus, not without a tone of solemn remonstrance, accuses her of a life of loose morals. It is implied that the first five husbands were conventionally allowable; but the suggestion is that, either by divorce or wanton rushing to further nuptials if the former had been ruptured by death, her character had been ever deteriorating until, under present circumstances, she was committing an overt act of illegality and impurity.