If the pope was opposed to Italian unification then why did not Italy label him as a traitor, end the papacy and not give him any land?
Italy had indeed brought the Pope's temporal rule to an end by annexing Rome (the last Papal stronghold) on 20 September, 1870; but the Pope refused despite the freedoms - such as the right to receive foreign ambassardors, monetary compensations, being granted the inviolability of His person, etc. - and assurances passed by the new Italian Parliament, to recognise the new state of things.
This led to a situation - the Roman Question - in which Italian Catholics were forbidden by their own Church to participate in the new country's political sphere, even if such prohibitions gradually came to be ignored, and by the early '900s were unattended by pretty much everybody (also due to the new Pontiffs' more conciliant stance).
[...] why did not Italy label him as a traitor, end the papacy and not give him any land?
As to why the new Kingdom didn't bring the Papacy to an end, the reason is very simple: nobody would have wanted that, least of all the King. Not only did the Pope have the support of almost a billion Catholics worldwide - thus making such a resolution extremely controversial and likely cause of diplomatic friction, perhaps even war - but the King's legitimacy came from ruling "By the Grace of God and the Will of the Nation". ^1 Not to mention that this would've probably led to further revolts, which would have made the then-ongoing military campaign against the brigands in the country's South look like a cake-walk.
Nobody wanted that to happen and what is more important, nobody would've gained anything from it...
...and this is true even today, too!
Why did Italy give the pope land in the Lateran Treaty?
Until 1929, the Kingdom and the Holy See simply didn't recognise each other until Mussolini - in a bid to please the more devout strata of the population - signed the Lateran Treaty, thus establishing the modern-day Vatican City; political convenience, coupled with the ever-present quest for consensus, was what made the Fascist regime do it.
^1 From the very first page of the Statuto Albertino, the Kingdom's constitution.