That trigger doesn't work for detect thoughts (normally).
The spell detect thoughts requires the use of an action to read the enemy's mind, either as part of the action you use to cast the spell or as a separate action on each turn of the spell's duration (see the following description of the spell, emphasis mine). We'll call that the mind-reading action.
For the duration, you can read the thoughts of certain creatures. When you cast the spell and as your action on each turn until the spell ends, you can focus your mind on any one creature that you can see within 30 feet of you.... You initially learn the surface thoughts of the creature--what is most on its mind in that moment.
Whether it's at the time of casting or later during the spell's duration, you can only read the enemy's mind when you spend that mind-reading action. Nothing in the spell implies that it establishes an ongoing mental connection that continuously feeds you information (see caveat below) like some other telepathy feature might. Rather, you get the information only when you take the mind-reading action.
Now, suppose you use your action on your turn to take the Ready action and specify the trigger "when the enemy magic user decides to cast a spell at me." The problem is that you would only be able to perceive the trigger while reading the enemy's mind, but you can read their mind only when spending that mind-reading action. This means you would have to have a way to take the mind-reading action on the enemy's turn while they are making a decision to cast the spell, but you can't take an action on another creature's turn (normally). So the trigger would not be perceivable.
Caveat: It depends on the interpretation of the spell.
Some readings of the spell may differ with what I've presented based on this portion.
When you cast the spell and as your action on each turn until the spell ends, you can focus your mind on any one creature that you can see within 30 feet of you.... You initially learn the surface thoughts of the creature--what is most on its mind in that moment. As an action, you can either shift your attention to another creature's thoughts or attempt to probe deeper into the same creature's mind.
Some DM's may interpret this to mean that there is indeed an ongoing mental connection that continuously feeds you information (the enemy's surface thoughts) once you have locked your "focus" on them. In that interpretation, my answer is basically nullified.
I don't believe the ongoing connection exists because it's not stated in the spell, but your interpretation may differ, so use your own judgment and precedent at your table about how detect thoughts is interpreted to work:
If you agree with my interpretation, the trigger won't work.
If you agree with this alternative interpretation (or if you just think the use of detect thoughts for this trigger is cool/useful/interesting and don't care about the "lexical gymnastics"), the mind-reading action must still be made before the Ready action is taken but does not need to be made on the enemy's turn, so the trigger would work.
Note: Other forms of telepathy may differ.
Not every feature granting a form of telepathy involves the same action restriction as detect thoughts, so this answer doesn't preclude other forms of telepathy that could perceive this trigger. The different telepathy features vary quite a bit, so consider asking another question if there is another telepathy feature of interest, because the answer would most likely vary.