I understand that you agree that masturbation is acceptable for non-malicious reasons, such as relieving one's self from excess semen. However, if the goal of doing so is to relieve sexual tension, is it still sinful? I mean after passing by someone attractive and getting an erection, is it all right to "calm myself down" through masturbation?
When semen builds up in your body, your sexual tension (your desire for sex) rises to encourage you to ejaculate. That tension can be relieved through wet dreams or masturbation, so long you are not using pornography or lustful thoughts to get yourself sexually aroused. "For this is the will of God, your sanctification: that you should abstain from sexual immorality; that each of you should know how to possess his own vessel in sanctification and honor, not in passion of lust, like the Gentiles who do not know God" (I Thessalonians 4:3-5).
Just because you get an erection, it doesn't follow that you need to relieve yourself. Erections are a normal part of being a male, though they can be annoying and too frequent when you are young. Erections can happen even when you are not in a sexual situation or not thinking about sex.
A problem that can arise from masturbating because you were aroused by the sight of someone is that it is too easy to use the memory of what you saw to stimulate yourself. The result is that you are then imagining a sexual scene with the person while you are masturbating. "But I say to you that whoever looks at a woman to lust for her has already committed adultery with her in his heart" (Matthew 5:28). Lust for something sinful is still a sin.
If you find your thoughts straying into realms it should not go, then, yes, it is an indication that you are getting close to needing to ejaculate. But separate the events from relieving yourself.