As a general rule hardware is good when you have a relatively simple task that you need to do very quickly/frequently. Software is good when you have a more complex task that is not so speed-critical.
Unmanaged switches do pretty much everything in hardware. Their job is a simple one, add MAC addresses to a table, match MAC addresses against that table. It's simple but it needs to be fast and cheap, dedicated hardware is the order of the day. It wouldn't surprise me if there were some tiny processors inside doing initialisation stuff but if there are they aren't visible from outside.
Managed switches have a CPU to handle the management side of things. Building the management interface in hardware would be prohibitively expensive both from a development and production point of view. It would also make it impossible to fix bugs or add features after the hardware was produced.
A similar principle applies to high end routers, the actual high speed data forwarding is handled by dedicated hardware but the management side of things including talking to other routers is done in software.