Guarding your heart against sexual immorality is one of the primary functions of the wisdom of God in the lives of his children. You cannot underestimate the danger sexual immorality poses to your soul, especially adultery.
What evil people do is flip the script on what is right, just, and fair. They twist the truth in a knot in an attempt to justify evil and condemn righteousness. Then, they try to pull you into that same way of evil with them. God's wisdom, in contrast, gives you a proper understanding of goodness, righteousness, justice, and equity, and wise people will try to pull into the way of life.
God is the source of all life. Therefore, when you walk in his ways, that very obedience to his word becomes a shield around you, guarding you against the forces of death, sin, and evil. When God gives you wisdom, when he opens your heart to understand him and his word, inherent to that knowledge is the protection of your soul.