There is a lot of variety when it comes to the different types of programmers. In general, is beneficial for a programmer to learn how to build a compiler? In what cases would
Yes, it is a good idea. Learning how all this stuff works can only benefit the programmer. I've wrote a BASIC compiler in SX ASM and learned a ton from it.
As someone else mentioned though, there's many degrees of programmers and knowledge. A web dev who is mainly into markup & scripting languages probably wouldn't benefit as much from it as a hardcore C or ASM programmer who writes embeded systems software - that's not to say it wouldn't be useful knowledge though.
Re-inventing wheels is always useful for educational value.