user16534: Does Buddhism preach absolute non-violence? Or is there any instance where Buddha had thought that violence can become a necessity under certain situations?

user254: It's hard to "prove a negative" e.g. to prove that someone never said something (e.g. that violence is necessary).
One way to try to do that is to quote an expert on the subject.
In Getting the Message, Thanissaro Bhikkhu wrote,

When asked if there was anything whose killing he approved of, the Buddha answered that there was only one thing: anger. In no recorded instance did he approve of killing any living being at all. When one of his monks went to an executioner and told the man to kill his victims compassionately, with one blow, rather than torturing them, the Buddha expelled the monk from the Sangha, on the grounds that even the recommendation to kill compassionately is still a recommendation to kill — something he would never condone.

The next sentence of that quote is,

If a monk was physically attacked, the Buddha allowed him to strike back in self-defense, but never with the intention to kill.

I think that latter means "if trapped, to strike a blow, desiring freedom".
So I guess that's a limited, perhaps a harmless, violence.

user11009: The way I understand what Buddha taught was a set of natural law, not a man-made law. (except for Vinaya perhaps)
What Buddha taught was Kamma and Vipaka.
Angulimala killed many people but still became an Arahant.

user8157: The Buddha generally taught the Buddhist Path rather than a formula for all of society. For example, in many of his teachings, he said those who break the law get executed by the King. The Buddha never taught the King was wrong for executing criminals. For example:

‘This person has murdered a man or a woman.’ Then the kings have them
arrested for killing, and execute, imprison, or banish them, or do
what the case requires.
AN 5.178

While it is unlikely the Buddha actually taught DN 26, DN 26 says:

But sire, what are the noble duties of a wheel-turning monarch?’
‘Well then, my dear, relying only on principle—honoring, respecting,
and venerating principle, having principle as your flag, banner, and
authority— provide just protection and security for your court,
troops, aristocrats, vassals, brahmins and householders, people of
town and country, ascetics and brahmins, beasts and birds.

Buddhism generally makes a distinction between itself & the rest of society. Buddhists should do their very best to refrain from violence.

user-1: No, householder Somanna, the Buddha and all wise approve that one thing should be killed, and only that:
Having killed what
    do you sleep in ease?
Having killed what
    do you not grieve?
Of the slaying
of what one thing
    does Gotama approve?
[The Buddha:]
Having killed anger
    you sleep in ease.
Having killed anger
    you do not grieve.
The noble ones praise
the slaying of anger
    — with its honeyed crest
    & poison root —
for having killed it
    you do not grieve.
Ghatva Sutta
Without need to have any doubt, if hearing or seeing that someone approves harming, encourages to such by signs and words or even performing such, that such person is not even near related to the Buddha, wise and their following, but harmful thieves in this world.
Those who have doubts, regard them as not having found refuge in the tripple Gems jet, how much ever they use the Gems, even tell that they are Buddhist, knowing, and follower.
May one be careful and blessed to never assosiate with fools and bad friend.
As already quoted, not all are capable in getting the message.
The Simile of the Saw, is possible the most famous collection on it.
Not for any purpose:

"What do you think Dhanañjani? There is the case where a certain person, for the sake of his mother & father...for the sake of his wife & children ... his slaves & workers ... his friends & companions ... his kinsmen & relatives ... his guests ... his departed ancestors ... the devatas ... the king, ...There is the case where a certain person, for the sake of refreshing & nourishing his body,..., does what is unrighteous, does what is discordant. Then, because of his unrighteous, discordant behavior, hell-wardens drag him off to hell. Would he gain anything by saying, 'I did what is unrighteous, what is discordant, for the sake of my mother & father. Don't [throw] me into hell, hell-wardens!' Or would his mother & father gain anything for him by saying, 'He did what is unrighteous, what is discordant, for our sake. Don't [throw] him into hell, hell-wardens!'?"
"No, master Sariputta. Even right while he was wailing, they'd cast him into hell."...

Harmlessness is one of the three factors of right effort,following right view.
What ever might appear as harmfull, like rebuking fools, there by the words, right speech,  of compassion ends what ever conductive support can be given for one who acts (by thought, words and speech) for his longtime disadvantage.
(Note: this is not given for trade, exchange, stacks or entertainment, but only as means to escape this binding wheel)

16534: <p>Does Buddhism preach absolute non-violence? Or is there any instance where Buddha had thought that violence can become a necessity under certain situations?</p>
 254: <p>It's hard to "prove a negative" e.g. to prove that someone never said something (e.g. that violence is necessary).</p>

<p>One way to try to do that is to quote an expert on the subject.</p>

<p>In <a href="https://www.accesstoinsight.org/lib/authors/thanissaro/gettingmessage.html" rel="nofollow noreferrer">Getting the Message</a>, Thanissaro Bhikkhu wrote,</p>

<blockquote>
  <p>When asked if there was anything whose killing he approved of, the Buddha answered that there was only one thing: anger. In no recorded instance did he approve of killing any living being at all. When one of his monks went to an executioner and told the man to kill his victims compassionately, with one blow, rather than torturing them, the Buddha expelled the monk from the Sangha, on the grounds that even the recommendation to kill compassionately is still a recommendation to kill — something he would never condone.</p>
</blockquote>

<p>The next sentence of that quote is,</p>

<blockquote>
  <p>If a monk was physically attacked, the Buddha allowed him to strike back in self-defense, but never with the intention to kill.</p>
</blockquote>

<p>I think that latter means "if trapped, to strike a blow, desiring freedom".</p>

<p>So I guess that's a limited, perhaps a harmless, violence.</p>
 11009: <p>The way I understand what Buddha taught was a set of natural law, not a man-made law. (except for Vinaya perhaps)
What Buddha taught was Kamma and Vipaka.
Angulimala killed many people but still became an Arahant.</p>
 8157: <p>The Buddha generally taught the Buddhist Path rather than a formula for all of society. For example, in many of his teachings, he said those who break the law get executed by the King. The Buddha never taught the King was wrong for executing criminals. For example:</p>
<blockquote>
<p>‘This person has murdered a man or a woman.’ Then the kings have them
arrested for killing, and execute, imprison, or banish them, or do
what the case requires.</p>
<p><a href="https://suttacentral.net/an5.178/en/sujato" rel="nofollow noreferrer">AN 5.178</a></p>
</blockquote>
<p>While it is unlikely the Buddha actually taught <a href="https://suttacentral.net/dn26/en/sujato" rel="nofollow noreferrer">DN 26</a>, DN 26 says:</p>
<blockquote>
<p>But sire, what are the noble duties of a wheel-turning monarch?’</p>
<p>‘Well then, my dear, relying only on principle—honoring, respecting,
and venerating principle, having principle as your flag, banner, and
authority— <strong>provide just protection and security</strong> for your court,
troops, aristocrats, vassals, brahmins and householders, people of
town and country, ascetics and brahmins, beasts and birds.</p>
</blockquote>
<p>Buddhism generally makes a distinction between itself &amp; the rest of society. Buddhists should do their very best to refrain from violence.</p>
 -1: <p>No, householder Somanna, the Buddha and all wise approve that one thing should be killed, and only that:</p>

<p><code>Having killed what
    do you sleep in ease?
Having killed what
    do you not grieve?
Of the slaying
of what one thing
    does Gotama approve?</code></p>

<p><code>[The Buddha:]
Having killed anger
    you sleep in ease.
Having killed anger
    you do not grieve.
The noble ones praise
the slaying of anger
    — with its honeyed crest
    &amp; poison root —
for having killed it
    you do not grieve.</code></p>

<p><a href="http://zugangzureinsicht.org/html/tipitaka/sn/sn01/sn01.071.than_en.html" rel="nofollow noreferrer">Ghatva Sutta</a></p>

<p>Without need to have any doubt, if hearing or seeing that someone approves harming, encourages to such by signs and words or even performing such, that such person is not even near related to the Buddha, wise and their following, but harmful thieves in this world.</p>

<p>Those who have doubts, regard them as not having found refuge in the tripple Gems jet, how much ever they use the Gems, even tell that they are Buddhist, knowing, and follower.</p>

<p>May one be careful and blessed to never assosiate with fools and bad friend.</p>

<p>As already quoted, not all are capable in <a href="http://zugangzureinsicht.org/html/lib/authors/thanissaro/gettingmessage_en.html" rel="nofollow noreferrer">getting the message</a>.</p>

<p><a href="http://zugangzureinsicht.org/html/tipitaka/mn/index_en.html" rel="nofollow noreferrer">The Simile of the Saw</a>, is possible the most famous collection on it.</p>

<p>Not for any purpose:</p>

<blockquote>
  <p>"What do you think Dhanañjani? There is the case where a certain person, for the sake of his mother &amp; father...for the sake of his wife &amp; children ... his slaves &amp; workers ... his friends &amp; companions ... his kinsmen &amp; relatives ... his guests ... his departed ancestors ... the devatas ... the king, ...There is the case where a certain person, for the sake of refreshing &amp; nourishing his body,..., does what is unrighteous, does what is discordant. Then, because of his unrighteous, discordant behavior, hell-wardens drag him off to hell. Would he gain anything by saying, 'I did what is unrighteous, what is discordant, for the sake of my mother &amp; father. Don't [throw] me into hell, hell-wardens!' Or would his mother &amp; father gain anything for him by saying, 'He did what is unrighteous, what is discordant, for our sake. Don't [throw] him into hell, hell-wardens!'?"</p>
  
  <p>"No, master Sariputta. Even right while he was wailing, they'd cast him into hell."...</p>
</blockquote>

<p>Harmlessness is one of the three factors of <a href="http://zugangzureinsicht.org/html/ptf/dhamma/sacca/sacca4/samma-sankappo/index_en.html" rel="nofollow noreferrer">right effort</a>,following <a href="http://zugangzureinsicht.org/html/ptf/dhamma/sacca/sacca4/samma-ditthi/index_en.html" rel="nofollow noreferrer">right view</a>.</p>

<p>What ever might appear as harmfull, like rebuking fools, there by the words, <a href="http://zugangzureinsicht.org/html/tipitaka/mn/mn.058.than_en.html" rel="nofollow noreferrer">right speech</a>,  of compassion ends what ever conductive support can be given for one who acts (by thought, words and speech) for his longtime disadvantage.</p>

<p><em>(Note: this is not given for trade, exchange, stacks or entertainment, but only as means to escape this binding wheel)</em></p>
