The current status of Gibraltar is "British Overseas Territory". It is not part of the UK, but it is part of the EU. The UK controls Gibraltar's Foreign and Defence policy, but it is self-governing in other matters.
There is no indication that the UK government wishes Gibraltar to remain in the EU, nor is there any indication that the EU would be willing to consider it for membership. Spain would never allow for it, and Spain does have a veto on new members.
There is every reason to believe that the UK government would be happy to allow the Gibraltese to reunite with Spain, if that wish was clearly expressed, but several referenda have been held that show that the Gibraltese want to remain linked to Britain.
If both the EU-27 and the UK (and the Gibraltese) wanted Gibraltar to remain in the EU this could be negotiated. It would be a novel arrangement. While it is possible for an overseas territory to not be a member (the arrangement of, for example, Jersey, the Falklands and Greenland), and it is possible for an overseas colony to be in the EU (for example, the French colonies like Martinique) there is no example in which a colony is a member, but not the controlling state. Nevertheless, with political will, this could be negotiated.
But, since the UK, the EU and Spain would all be against such a position, it will never happen.
It is also unlikely that it could be "sold for a price that Spain doesn't have." Spain is a large economically developed country. Who else would want to buy Gibraltar at an artificially inflated price?