L.,
While I realize that these situations are never easy, in my opinion, you need to show your 12 yr old who is boss. He needs to learn that what you say goes, and this is not a democracy, it's a dictatorship (in a sense). You make the decisions that you feel are best. It sounds to me that your Ex is trying to be your son's 'friend' vs. a Parent. This never works -- you can't be both - you need to be a Parent first and you be his friend later (when he's older and grown and on his own).
First thing I would do is call my Ex and tell him that he needs to bring him home and stay out of it - this situation is between you and your son. If he refuses, tell him the next step you will take will be to involve the police and have a copy of your Divorce Decree & Custody agreement in hand. (It sounds like from your post that you just agreed to this and it was not formally changed through the court). You will have to go to his house, but the Police will show up and force him to turn your son over. It may sound harsh, but your Ex needs to learn that he can't 'rescue' the kids just because they don't like something you've done. He also needs to learn that HE has to follow the rules and it will be good for both your Ex and your Son to learn that they have to follow the rules & laws - they can't just do what they want.
If his agreeable and will bring him back, then I would have a conversation with him and let him know that you don't appreciate his behavior and actions, remind him that this verbal agreement was a privilege and it's no longer going to happen, remind him that your son's grades are slipping and this is why it's going back to the original arrangement, and the next time your son calls him and he decides to play the 'rescuer', you'll involve the police.
Once you have your son, I'd sit him down and tell him these things: 1) remind him of your agreement and the reason why you said he could only go there on weekends. 2) Tell him that while you understand that he wants to spend time with his dad, the arrangements was not working out, his grades were slipping - and until he takes responsibility for himself and his grades - he will only see his Dad on the designated weekends. Let him know that he does have a way to change the situation - but that along with getting older means taking responsibility for himself and his education and beginning to learn to act like an adult. 3) Tell him that under no circumstance is he to call his dad to pick him up from school w/out discussing it first with you. Let him no the consequences of him doing this and what will happen. He can call his Dad to talk with him anytime, but this is clearly unacceptable. 4) Lastly, Let him know that due to his behavior and his actions, what the consequences of his actions are. Take away privileges, ground him, whatever you do for discipline with him.
You son isn't going to like any of this. He'll see you as the bad guy. But it'll pass. The most important thing in all of this is let him know that you love him, but he needs to learn who is boss.
He's testing you too - to see what your reaction will be. So stand firm, and don't allow this to just slide by. Otherwise, you'll have even more problems (and possibly worse) in the future.
--K.