It is generally safe to use third-party charging cables with your MacBook Pro M2, as long as they are USB-C cables that support the power delivery standards required by your laptop. However, it is important to note that not all third-party cables are created equal and some may not meet these requirements, which could potentially damage your MacBook's battery or other components.
If you want to use a magnetic MagSafe charging cable with your MacBook Pro M2, you can purchase a third-party cable that is designed to work with USB-C ports. Just make sure that the cable you choose is rated for the appropriate power output and supports the same charging standards as the original cable that came with your MacBook Pro.
Using a third-party charging cable is unlikely to reduce your battery health, as long as the cable is of high quality and is used properly. However, it's always a good idea to use official accessories from Apple whenever possible to ensure the best performance and longevity of your MacBook Pro.