Has a team ever declared whilst still trailing the opposition in a First Class / Test Match before?
While it may seem counter intuitive, seemingly giving your opponent an advantage going into the third innings of a game, there may actually be advantages to doing so.
For example: your team are trailing by, say, 40 runs. The current weather, and for the upcoming sessions, is very favourable towards bowling (overcast, a stiff breeze, quite humid etc.), but will likely improve for batting afterwards. The pitch also seems to going flat, meaning that batting last should be "easy".
You, as captain, may see an opportunity to get the opposition in to bat, and look to bowl them out cheaply, utilising the favourable conditions, and then having a relatively modest final innings chase on a flat pitch with good batting conditions.
Another example is if you know the final day of the game is likely to be lost to rain, and you need to force a win, and you wish to progress the game so you can getting into the final chase as soon as possible.