If anything, the average terrorist is probably smarter than the average member of their surrounding societies, since you need a minimum amount of education to understand the ideology motivating the terrorism. Don't forget that Taliban literally means "students." The number of times someone tried and failed to conquer Afghanistan suggests that it's not an easy feat that any fool could have done, but the Taliban managed to do it twice.
Fighting a much more numerous enemy may seem stupid, but if you really believe your ideology, any odds of success are better than none. Think open-source developers competing with commercial offerings maintained by huge teams. Terrorists building IEDs when their enemy has a full military-industrial complex are much the same. They just really believe their ideology. On this, https://www.astralcodexten.com/p/your-book-review-nine-lives is a good read.
> Fighting a much more numerous enemy may seem stupid, but if you really believe your ideology, any odds of success are better than none.
Embracing and believing this destructive ideology itself in the first place, when you could devote your life to so many better[1] things, is the sign of stupidity I mean.
Believing that God wants you to murder other people (heck, even babies) over things such as who's worshiping Him correctly... stupid.
1. Better for... you name it: Your quality of life, welfare of other human beings, economically, spiritually, environmentally.