In no particular order….
”Due to a software error”? Could you explain what that means in this context; about what happened?
Could be a hardware problem, could be a storage corruption, could be add-on anti-malware, could be a protected app.
If the target app is among the protected (including all pre-installed apps), it cannot be deleted or overwritten. Which app?
For anti-malware and app collisions, and for reporting that can highlight some hardware issues, download and run EtreCheck, and share the report to the clipboard. Then open a new reply here, select the Additional Text button that looks like a printed page, and paste the hardware and software configuration report into that additional-text text input box, and post it here.
If the volume is corrupted, the path is usually a backup and a reinstall and a migration.
Do Apple Diagnostics report anything?
Use Apple Diagnostics to test your Mac - Apple Support
If the hardware is failing, it’s a repair (not usually economical on a 2015-era Mac, nor on a 21.5” iMac model more generally), or migrating to external SSD storage, or replacement with a more recent or current Mac, such as with the 24” iMac.