You don't have to tell Spain or anyone else. Enforcement is effected by examining passport stamps. There is an electronic system in the works, but since it's not yet in operation, you're obviously not in it.
When you return to the Schengen area, you'll want to have some evidence that you were in Gibraltar on or before the 89th day after you entered the Schengen area, in case the border officer notices that you don't have an exit stamp matching your entrance stamp.
Having said that, there are some misconceptions in your question that ought to be noted:
I ... cannot stay in the EU for longer than 3 months per 6 month period.
That isn't quite it. First, it's 90 days per 180-day period, which is slightly more precise.
Furthermore, the restriction applies to the Schengen area, not the EU. Notably, you can spend more than three months in Ireland, and the 90-day restriction is counted separately for the other EU countries that aren't in the Schengen area (Bulgaria, Croatia, Cyprus, and Romania, if memory serves). (There are also some non-EU countries in Schengen area, namely Iceland, Norway, Switzerland, and Liechtenstein.)
Finally, note that if you entered Gibraltar on the 90th day after you entered the Schengen area, you have to remain outside the Schengen area for 90 full days before you can re-enter. On the other hand, if you went to Gibraltar on the 89th day, you can enter the Schengen area (for example to transit) as long as you leave before midnight on the day of arrival.
Note that days are counted as calendar days. If you enter at 11:55 p.m. and leave ten minutes later, that counts as two days. If you enter at five minutes past midnight and leave 23 hours and 50 minutes later (or ten minutes later, for that matter), that counts as one day.