If you have two inputs and one output, it's often useful to make a logic table:
│ 0 │ 0 │ 0 │
│ 0 │ 1 │ ? │
│ 1 │ 0 │ 1 │
│ 1 │ 1 │ 0 │
IN1 is the minecart on the detector rail,
IN2 is your release signal,
OUT is the piston. The output for the case of no minecart on the detector rail and the release signal being pressed doesn't matter, so I put a question mark there.
The logic table tells us that you need either an
XOR gate or an
AND gate with the second input inverted. An
AND gate with one input inverted can be built cheaper and more compact, so I'll take that as an example.
Since the most common
AND gate in Minecraft inverts both inputs, uses redstone dust to check if either is on (an
OR gate) and then inverts the signal again, you basically just need to build the regular
AND gate with one redstone torch less:
The top left lever is your detector rail input, the bottom middle one is your "release" signal. The lamp only turns on (the piston extends) if there is an input from the top right (minecart on track) and no bottom middle input (release signal). This should also be a more "sane" behaviour than the
XOR gate, which would have extended the piston on the release signal if there was no minecart on the track.