But so is practicing law. You can be an expert on bankruptcy law, or media/entertainment law, etc.
The idea of the bar exam is that the expectation is that any lawyer, at the point of passing the bar, the point at which they actually become a lawyer, have a solid understanding of most, if not all, general aspects of the law. I know of one exception, patent law, that is covered in a separate exam, but I'm not aware of other exceptions.
If they later choose to invest time and energy into specializing, and later forget some of the other more niche concepts of the law they don't practice, that's deemed as being okay.
Like software engineers, lawyers are not bound to one practice area, and some (especially in smaller towns) have overlap in several areas.
Yet when it comes to examination, the legal industry has managed to create a "one to rule them all" for grant someone admission to practice law. And it's generally effective in doing so. In theory, the same would be possible for another large career field that share core concepts in common, for all the jobs in that field.
What prevents a general examination to be designed and formulated for software programming work? We, too, work all over the place, yet there is no standard "bar exam" for programmers. Maybe the field is still not mature enough and we have to wait it out a couple more years?