This is a simple patch that adds a sound effect when Magikoopa appears and disappears in levels.
You're almost there, there's just one minor oversight which keeps me from approving this.
The code you hijack is a bit jumbled up, which is probably why you've made this mistake. Tracing the possible paths through it shows that, in order for the Magikoopa to work properly, the A register must not be $40 when you get to $01BE86 (your return address) through $01BE80. In the vanilla game, this is always true because $01BE80 will only be executed if A is zero due to the branch at $01BE7E. Additionally, the code at $01BE96 uses the value loaded at $01BE7B to index a table, thus introducing the possibility of the animation being broken.
Your patch clobbers the A register to store the sound effect. In most cases, this will have no practical consequences. No valid vanilla sound effect has a value of $40 (so the branch at $01BE88 will not break) and all valid vanilla sound effects produce a 0 when shifted right 6 times at $01BE96 (so the animation will never break). Regardless, this could be triggered by the end user if they use custom sound effects, which is why I'm treating this as a rejection reason.
In spite of the long-winded explanation, fixing this is actually quite simple. The Y register is pretty much completely free in the code you're hijacking, so you should use Y instead of A to store the sound effect. Do that and this patch will be acceptable.
As a side note, your code never messes with the data bank, so using freecode is not needed. It's safe to change it to freedata.