I was born a muslim and now I don’t believe in anything, that is why anything that I’m going to say here is my take on the matter that is derived from my knowledge in arabic, my Islamic upbringing and the fact that I grow up in an Islamic country.
The two paragraphs that you’ve used are mis-translated and missing context, the literal translation of script changes that intent of the paragraph and the missing context make it sounds like a rule that it should be followed every muslim, below is a better translation and some context that would help me lay down my take on the matter:
First one from Surrat Al-Anfaal
The context in summary after muslims victory in the first major war in Islam (Bader), the army had a dispute about to whom should the spoils of war go to, Allah (a.k.a god) is telling them that you should split it equally since he/she sent angels to fight with them and without that they wouldn't have won.
Aya: (Al-Qurtuby explanation)
إِذْ يُوحِي رَبُّكَ إِلَى الْمَلَائِكَةِ أَنِّي مَعَكُمْ فَثَبِّتُوا الَّذِينَ آمَنُوا ۚ سَأُلْقِي فِي قُلُوبِ الَّذِينَ كَفَرُوا الرُّعْبَ فَاضْرِبُوا فَوْقَ الْأَعْنَاقِ وَاضْرِبُوا مِنْهُمْ كُلَّ بَنَانٍ
God instructed his\her angles to join the fighters, that he\she is on there side and that the believers are going to win this battle and that him\her is going to strike fear in the hearts of the non-believers, stay put and fight them ferociously until the end (the last part is considered to be him/her talking to both angels and believers).
It might feel that there are alot missing and this translation doesn’t make much sense, but languages in general uses analogies, for instance “the buck stops here” doesn’t mean there is an actual buck running around.
Arabic in specific uses analogies alot for instance the literal translation from the surrah “ سَأُلْقِي فِي قُلُوبِ” would be “spilling fear into the hearts”, same with with ‘strike over their heads’ mean that you have to fight ferociously, and “strike their fingers” means don’t stop until they can’t fight anymore.
Second one from Surrat Muhammed
فَإِذَا لَقِيتُمُ الَّذِينَ كَفَرُوا فَضَرْبَ الرِّقَابِ حَتَّىٰ إِذَا أَثْخَنتُمُوهُمْ فَشُدُّوا الْوَثَاقَ فَإِمَّا مَنًّا بَعْدُ وَإِمَّا فِدَاءً حَتَّىٰ تَضَعَ الْحَرْبُ أَوْزَارَهَا
If you meet the non-believers in battle (according to Al-Qurtuby explanation people who worships Idols and it does not mean monotheistic religions like christians and jews), fight them and if you killed a lot of them start taking hostages.
Then exchange hostages (according to stories they had to either teach 10 illiterate muslims to be released, or pay money if the hostage is rich) or release them if they have nothing, repeat until the war ends.
The beheading analogy in here is meant to show that you should show courage in battle and to not be soft heart, something like saying (you should kick the shit out of them).
also worth mentioning that this is not the complete aya but and that the rest doesn’t really have anything to do with your question.
If you feel this isn’t sufficient, please let me know and I’ll provide a word by word meaning, and references to language proof from sources other the Quran.
With all that said Islam still use beheading as a punishment and it is mention in several place in both Quran and Hadith, at the top of my head it is used to punish murders and people who leaves Islam, monotheistic religions in general have special punishments for special sins, lets take stoning for example it was reserved in the old testament for necromancy, blaspheming the name of the lord and idolatry among others, and in islam it is the punishment for adultery.
And that takes us to why some of those muslims condemn beheading: -
As a punishment because it is the 21st century and Islam came 14 hundred years ago and some of the methods that was acceptable back then now they are not, few islamic countries uses beheading nowaday and hopefully not for long.
Also the beheadings that are done by somebody like Al-Zarqawi aren’t something that muslims should be held accountable for (same as holding all mexicans accountable for el chapo), and believe me muslims are scared shitless back there from such people (since the majority of the beheaded are actually muslims that Al-Zarqawi disagreed with), think of such groups as gang that like to use religion to hire ignorant mislead muslims.