Is it dangerous to mix RAM?
Dangerous? No. Good? Maybe, maybe not.
There's more to RAM than just type (DDR4) and stick capacity (8 GB). There's also clock frequency, timings and physical composition.
The clock is determined by the motherboard, but some RAM modules can work with faster clocks than others. A module reports supported clock frequencies to the motherboard. The faster the clock, the better, because the RAM module has more occasions to take requests or respond to them.
Timings are also reported by the memory module. There's a bunch of them. The lower they are, the better, because timings determine the memory latency (essentially how many clock ticks something takes) and you want to keep the latency low.
The thing is, when you mix memory modules with different frequencies and timings, you get the worst of both worlds: all modules have to run on the clock and timings appropriate for the slowest one.
Physical composition and wiring of modules can affect the compatibility. RAM is finicky sometimes and different modules may or may not work together. There's only one way to check it though, and there's no risk.
Your CPU almost certainly has 2 memory channels, so just the fact of giving it 2 extra memory modules doesn't give you any performance gains. If you need more than 16 GB, consider adding these two older modules, but keep in mind that overall RAM performance can suffer if the clock and timings don't match. It's better to have enough of slower RAM than not enough of faster RAM of course, but since most users don't actually need more than 16 GB you can consider sticking to just that much.
As long as it is all DDR4 this should work.
Except if the older RAM is too slow for your new computer. In that case the computer will give some beeps on startup and will do nothing else.
Just remove the extra RAM in that case. Nothing bad will happen.
Question is if you actually need the 16 to 32 GB upgrade. Most home-users typically only use 6 to 8 GB, maybe 12 if they really try hard.
If you run very memory demanding applications (e.g. multiple virtual machines. Photoshop with large images) it may be beneficial.
Please note: Your older RAM is most likely a little slower than the new RAM. Most computers will in that case use the slowest RAM speed for ALL RAM in the machine. This is usually not really noticeable. The benefit of the extra RAM (if your workload really needs it ) will outweight the slight loss of speed.