Like most devices or modifications you make to your car, the answer depends on the laws in your area at the time. We know of no states that outright ban putting a camera in your car. So, generally speaking, the answer is no, dash cams are not illegal. However, there are factors you should consider when choosing the best dash cam for your individual needs and plans.
For example, many states have restrictions banning mounting gadgets or obstructions on the windshield. In these regions, you may consider a dashboard-mount, a camera that replaces or fits over the rearview mirror or some other low-profile installation option. Other states limit where on the windshield you're allowed to mount gadgets. So, you might have to put your camera in a corner of the windshield rather than in the center to avoid a ticket in these states.
Some states' distracted driving laws prohibit dash cams with always-on screens, so consider one with the option to disable the display while driving or one with no display at all. Honestly, even if you're not afraid of law enforcement here, not having another screen glowing in your periphery while driving, especially at night, is a good idea.
Finally, you'll need to consider your state's privacy and surveillance laws. They typically don't apply to recording what's happening around your car while you're driving, but drivers for ride-hailing services who pick up passengers, owners who share their vehicles with other drivers or who install a camera that continues to record while they're away from the car should check their local laws to make sure they don't run afoul of the law.
As we mentioned earlier, this is particularly important for cameras that record audio, which could rub up against two-party consent laws governing audio eavesdropping.