Some applications simply do not "play nice" with being pinned to the Taskbar (some API issue), but there is a workaround. For example Notepad++ integrates easily every time, but File Explorer, Microsoft Edge, Brave, Visual Studio Code (and many others) do not.
To test this, unpin them from the Taskbar, then drag a shortcut or the executable onto the Taskbar to pin it, and for misbehaving apps, you will get duplicate icons when opening that app.
Reason 1 in this link is the cause, and applies whether I drag a shortcut or executable onto the Taskbar (i.e. proving that Reason 2 is not the cause).
Some taskbar pinned icons are duplicated when an instance of the application is running
The "Temporary Solution" listed there works. "Open the program, so that you have duplicate icons, then right click the duplicate icon (the new one) and "Pin to taskbar", then right-click the original and select Unpin this program from taskbar, then there will only be one pinned item from now on."
However, I don't really regard this as a proper solution, as it's a nuisance to have to do this and as yet, sadly, I do not have a way automate a fix for this (11+ year old issue, going by the date of the linked answer). If anyone has a way in PowerShell to properly pin items, that would be appreciated (note that all answers that use this method of pinning are completely broken, none of the answers on here work since 2019. https://stackoverflow.com/questions/31720595/pin-program-to-taskbar-using-ps-in-windows-10/74205500#74205500)