The imagery of violence against women in Ezekiel 16 and 23 does not actually condone such behavior in real life, nor is it to be taken literally. Rather, Ezekiel employs an extended metaphor to condemn Jerusalem for its foreign policy and foreign worship.
Jerusalem is referred to in the feminine, and is first compared to a baby, found by G-d.
(4) And as for thy nativity, in the day thou wast born thy navel was not cut, neither wast thou washed in water for cleansing; thou was not salted at all, nor swaddled at all. (5) No eye pitied thee, to do any of these unto thee, to have compassion upon thee; but thou wast cast out in the open field in the loathsomeness of thy person, in the day that thou wast born. (6) And when I passed by thee, and saw thee wallowing in thy blood, I said unto thee: In thy blood, live; yea, I said unto thee: In thy blood, live; (7) I cause thee to increase, even as the growth of the field. And thou didst increase and grow up, and thou camest to excellent beauty: thy breasts were fashioned, and thy hair was grown; yet thou wast naked and bare.
G-d raises Jerusalem as a daughter, even up through adolescence. Up until now, Jerusalem is referred to as G-d's daughter.
Once she comes of age, G-d takes Jerusalem as His wife.
(9) Then washed I thee with water; yea, I cleansed away thy blood from thee, and I anointed thee with oil. (10) I clothed thee also with richly woven work, and shod thee with sealskin, and I wound fine linen about thy head, and covered thee with silk. (11) I decked thee also with ornaments, and I put bracelets upon thy hands, and a chain on thy neck. (12) And I put a ring upon thy nose, and earrings in thine ears, and a beautiful crown upon thy head. (13) Thus wast thou decked with gold and silver; and thy raiment was of fine linen, and silk, and richly woven work; thou didst eat fine flour, and honey, and oil; and thou didst wax exceeding beautiful, and thou wast meet for royal estate.
G-d treats Jerusalem as His queen and beautifies her.
G-d condemns Jerusalem for engaging in foreign worship, and allowing others to perform acts of foreign worship within her gates.
Imagery of the harlot and adulteress refers to Jerusalem's foreign policy. Here, G-d condemns Jerusalem for allying with Egypt.
G-d condemns Jerusalem for attempting to ally or pay tribute to Assyria and Chaldea (Babylon).
Therefore, Jerusalem's "lovers," or allied super-powers, will descend upon her and defile her (destroy her).
Everything G-d gave to Jerusalem in the beginning of the chapter is then taken by Jerusalem's enemies, namely Babylon. We know this because Ezekiel lived at the time of the Babylonian destruction in 586 BCE.