You might want to actually troubleshoot the problem first. If you disconnect the wiring to the coupler and run the train, you can determine if the coupler is firing spuriously or if the problem is mechanical.
With the wiring disconnected, if the coupler stays closed, then the problem is electrical. If the coupler continues to open by itself, then the problem is mechanical within the coupler itself.
There are different fixes for each proplem. If the problem is mechanical, it can often be fixed by removing the knuckle and lengthening the spring that holds the plunger in place.
If the problem is electrical, then either the capacitor that MartyE mentioned will fix it, or you can look for a burned trace on a circuit board. Some K-Line locos fired their coupler spuriously when a board trace was blown.