Your question seems to be "How is this possible?" as a question of total incredulity, that a godly man like David could fall into such a sin. I'll come back to this.
Your next question is, "Why would a woman bathe before the king's royal palace or somewhere a king could see her?" She may have assumed that since the army was out to war, as was her husband Uriah, that David would surely be out with them, and so she didn't draw the curtains or whatever she normally did for privacy. If she did know David was still at home, maybe she wanted to seduce him. The text doesn't answer your question of why she bathed on her rooftop. So only speculation is possible. By the way, even if Bathsheba did something to deliberately catch David's eye, she was included in the genealogy of Jesus [Matthew 1], which is significant in several ways.
The last question about David's initiative in seeing her is equally unanswerable. He certainly did take the initiative to have her brought to his palace after he saw her. But whether he brought out his binoculars or what have you in order to spy on her, no one can say.
The big question then is "how was this actually possible?" And I'm assuming you say this because David is known as "a man after God's own heart", and the "anointed king of Israel", etc. So if he was pleasing to God, how could he stumble so dramatically?
You yourself answer this question when you say, "The sin is familiar to us." David wasn't great because he was morally strong or above others in his self-restraint. He was great because he knew God, loved God and cared for God's honor. According to St. Paul, he was great because he trusted in God to forgive his sins, [Romans 4:5-8, (quoting Psalm 32:1,2)]
5But to him who does not work but believes on Him who justifies the ungodly, his faith is accounted for righteousness, 6just as David also describes the blessedness of the man to whom God imputes righteousness apart from works:
7“Blessed are those whose lawless deeds are forgiven, And whose sins are covered;
8Blessed is the man to whom the Lord shall not impute sin.”
As great and heroic and faithful as David was, he was a man who desperately needed God's mercy and help, and KNEW he needed God. Thus, he was a truly humble man before God. His plea was recorded in [Psalm 51:1-4]:
1Have mercy upon me, O God,
According to Your lovingkindness;
According to the multitude of Your tender mercies,
Blot out my transgressions.
2Wash me thoroughly from my iniquity,
And cleanse me from my sin.
3For I acknowledge my transgressions,
And my sin is always before me.
4Against You, You only, have I sinned,
And done this evil in Your sight—
That You may be found just when You speak,
And blameless when You judge.
God doesn't prevent anyone from committing sin. He didn't put an electric fence around the Tree of the Knowledge of God and Evil, as you or I might have done; so even sinless Adam and Eve sinned. God expects us to exercise our free will in obeying His laws. When we don't, sin happens, especially to the "best" of us.