Security rules prohibit you from bringing a BB gun back in your hand luggage but I can't find anything that prohibits you from bringing one back in your hold luggage. However you would need to be prepared for some lengthy delays (both when leaving Spain and on arrival in the UK) when the X-ray scanners detect a 'weapon' in your luggage.
For a definitive answer, phone HMRC's helpline on 0300 200 3700 (Mon-Fri, 0800-1600).