The message you received was from GateKeeper, the Keystone MacOS anti-malware and security feature.
GateKeeper tries to keep you from marking "Bad Stuff" as "ok to execute". It was trying to tell you the item you were attempting to make executable was not 'notarized', was not signed by an Identified Developer or you had not provided specific information that this particular item was "known good" and you wished to install it anyway, regardless of consequences, but following the approved process.
WHAT FILE is mentioned in the message is of Utmost importance, and your query should not be about the general case. In General, such files should be discarded, just as the message suggests.
There are methods to make specific files that you wish to trust executable anyway. But this is NEVER the general solution. Each case should be dealt with specifically, on its own merits.
Depending on what file is being called out, resolution of this problem differs. If the file is unknown to you, it is essentially an attack, and your Mac is fending it off. If the file is known to you, but is from an Unidentified Developer, but you have reason to Trust the security of your computer to this software, there are documented methods in Apple articles to allow specific unidentified items to be marked as executable.
--------
Tossing Library files in the Trash has never been a solution recommended by Apple for this issue.
Installing third-party so-called virus scanners is a great way to bork your system, using up untold amounts of resources scanning for things that might be "threats" (whatever that means) and halting your computer when such a dubious "threat" is encountered, anywhere -- even as a stray pattern in a compressed graphics file.
If you got such advice (either to drag library files to the Trash or to Install Third-party Virus scanners) from a discussion on this forum, please provide a link to that discussion. I would like to ask the Hosts to flag or remove any such advice on the grounds that it is may be destructive or dangerous.
The approach you are espousing -- installing and using third-party virus scanners -- in NOT a recommended solution by anyone except third parties who profit from scaring you into installing their junkware.