I was really surprised when that happened in the middle of a playoff run for them and I'm still surprised by it. Maybe there is something about him they just didn't like or he didn't like about NYC?
They had him under contract still for a season and a half at that point.
remainder of the 2022 regular season: NY had such a big lead in the division at the trading deadline that Cashman made moves for the postseason and for future seasons. Montgomery's presence wasn't going to affect NY's 2022 regular season position, they were almost certainly going to end up with a top 2 seed in the postseason (and they did, despite somewhat collapsing down the stretch).
2022 postseason: NY believed Montgomery was their 5th best option for a postseason start, again I think correctly at the time. Cole, Cortes, Severino and Taillon were all ahead of him, so Montgomery was not going to be a factor in the 2022 postseason for NY.
2023 season: Montgomery's final season of control, but Cashman knew he'd be going after Rodon that winter and he wanted to give Schmidt a chance.
Bader somehow forgot how to hit, I don't think anyone would have really predicted that, but I liked the move then and I am fine with it in retrospect too.