Your pain has been poured out with a terrible honesty, and such honesty is not hidden from God. He is light, and in Him is no darkness at all, and He desires truth in the inward parts. It is better to tell Him plainly that you are wounded, sleepless, tormented by images you cannot drive away, and that you feel betrayed not only by a woman you loved but by God Himself, than to pretend a piety you do not feel. He can bear the cry.
You ask what God has done for you, and why you should follow Him when He did not turn back the clock and undo what was done. The ache you describe is real. To discover that one you loved gave herself, body and heart, to another, is a betrayal that cuts to the soul. It brings trauma and distrust and nights without sleep, and no honest pastor will tell you that the fact itself will disappear as if it never happened. God does not make facts vanish by pretending they did not occur. What He does is greater. He cleanses and He heals and He makes new. The blood of Jesus Christ cleanses from all sin, and when God pardons He does not call evil good, He washes the sinner and gives a new heart and a new life. The act of selling the body is not beautiful. The act of taking another man's wife is not beautiful. God has never called it beautiful. He calls it sin, and He judges it. But a prostitute who comes to Christ is washed, and is made beautiful not because her sin was beautiful, but because she is made new. That is what grace does. It does not celebrate the sin. It redeems the sinner.
You ask about that word to David, I gave you your master's house and your master's wives. That word has troubled many. Understand it rightly. When Saul died, his house and his household were entrusted to David as king, according to the custom of that time for the care and protection of the household, not as a license for lust. And when David later took Bathsheba, another man's wife, God did not change His standard and call it good. God sent Nathan the prophet to say, Thou art the man, and Thou hast despised the word of the Lord. God struck that sin with judgment, and David wept and repented in dust. God is not double minded. What He calls adultery in one place He calls adultery in every place. Marriage is the lifelong covenant of one man and one woman, and sex belongs within it alone. God has not altered that.
You ask if God has power to turn back time and make it so that your girlfriend never lay with another man. God is almighty and does all that is consistent with His holy nature, but He has not chosen to unmake history. He has chosen to atone for sin and to heal the wound that sin leaves. If He merely rewound the clock, the heart that could betray would remain unchanged. Instead He offers to wash the conscience, to take away the sting and the shame, and in the end to wipe away every tear, so that what was meant for evil is overcome by good. Recovery does not mean pretending the past did not happen. It means that the past no longer rules you, because God has come to dwell with you and to give you a future that is not defined by that betrayal.
You ask what God was doing while you suffered, whether He sat as a spectator. He did not. There is none like unto the God of Jeshurun, who rides upon the heaven in your help. The eternal God is your refuge. And to show that He is not distant from betrayal, He gave His own Son to be betrayed. Judas, one of the twelve, came with a kiss and handed Jesus over to His enemies. Your Lord knows what it is to be betrayed by one near to Him, to be wounded by a friend. He is not watching your pain from afar as entertainment. He entered it. On the cross He bore the weight of all sin and all sorrow, and He did so not for six hours to be measured against your sixty years as if to minimize your years, but because those hours carried an infinite weight of wrath for sinners, that He might be able to carry you through sixty years and through eternity. Low thoughts of God make pardon seem doubtful. High thoughts of God give hope, for if He could bear that, He can bear you.
You say God protected Sarah, Abraham's wife, and appeared to Pharaoh in a dream to keep her untouched, and you ask why He did not protect you. God indeed is sovereign and protects according to His wise counsel, and at times He restrains evil with a mighty hand. At other times He permits what He hates, and yet He will judge it with perfect justice, and He will use even the pain to work patience and experience and hope in those who trust Him. The fact that He did not prevent this evil does not mean your situation is small in His eyes or that He has no interest in you apart from His Son. His interest in you is seen precisely in His Son, for He gave His Son for sinners such as you and such as she, that you might be reconciled to Him. To look at the cross and say He does not care is to misread the cross entirely.
You say you prayed and nothing changed. Faith comes by hearing, and hearing by the Word of God, and it must be received with meekness. God is not deaf. He is the eternal God who does not change, and if He was your refuge years ago He remains your refuge now. Prevention is better than cure, and to trust Him before fear comes is blessed, but when fear has come, as it came even to David the warrior who slew Goliath, the cure is still to trust Him. David said, What time I am afraid, I will trust in Thee. Isaiah goes further and says, I will trust and not be afraid. May you be brought to that place where you can say, Should earth against my soul engage and storms of sorrow fall, I shall in safety reach my home, my God, my Heaven, my All. That confidence does not come from pretending you are not hurt. It comes from taking God at His word.
You ask why you must believe and treat others kindly if God is a tyrant who insists only on His own will. God is not a tyrant. He is holy and He is gracious, and He commands what is good because He is good. You are not asked to follow Him because power compels you, but because mercy invites you. Look unto me, and be ye saved, He says. Not look to your own good intentions, not look to your own heart which you hope is good at bottom, but look to Christ. Salvation is not by works, lest any man should boast. It is by faith in the merits of Christ. If you have never experienced being protected by God, begin here. Confess your own sin before Him, not only the sin done against you, but your own need of cleansing, for if we say we have no sin we make Him a liar. Own before Him what you are, and ask Him to cleanse you through the blood of Jesus. Then you will know His protection, not always as prevention of every wound, but as a refuge that holds you when wounds come, and as a healer who touches the suffering soul and healing comes at once.
Do not walk alone in this. Bring this wound into the light with a faithful pastor and with trusted brothers in Christ, and if the sleeplessness and depression press heavily, seek help from those skilled to care for both soul and mind. Keep yourself in the Word, where God shows His power and His glory, and pray not for God to bless what He calls sin, but for Him to bring repentance where there has been unfaithfulness, to bring healing to your mind, to teach you to live in purity and self control, and to prepare you, whether that means a restored relationship made right through repentance and a marriage covenant entered in holiness, or a different path where you are kept pure and made whole for whatever He has for you.
He who was betrayed lives to make intercession for the betrayed. He is able to put back every assault of the enemy and to put a new song in your mouth. Seek Him not as a useless or careless God, but as the great God and Savior who, when you are humbled, grants both pardon and healing.