Of course it's bad ethics to write stuff that only you can maintain. But if you built it, regardless of how well you documented it and how easy someone else could maintain it you're the current expert and by the sound of the OP the rest of the team is not in his league. So the employer thinks to cut costs now that the major work has been done and they're in 'maintenance mode'. That might work, for a while. And then in a few weeks when they want something a bit more elaborate it may very well turn out that letting the OP go was a mistake.
Being good at something (or at least, much better than your co-workers) is the other method you're looking for, no need to resort to evil stuff.
Likely this was reflected in the OPs salary, note that he's let go but his co-workers are not, so probably he was making more per hour than they. And now he'll make more per hour still and his former boss will be more than happy to pay once he realizes that OP could turn him down just as easy as he was let go.
And the OP's former boss gets to pay for the actual hours needed to implement the desired feature rather than a monthly cheque.
Could be a win both ways in that sense. OA gets a customer with a regular need and existing investment. Former boss gains flexibility and can show headcount reduction.
Being good at something (or at least, much better than your co-workers) is the other method you're looking for, no need to resort to evil stuff.
Likely this was reflected in the OPs salary, note that he's let go but his co-workers are not, so probably he was making more per hour than they. And now he'll make more per hour still and his former boss will be more than happy to pay once he realizes that OP could turn him down just as easy as he was let go.
Don't burn your bridges...