In that era, the Pope was a ruler over actual physical lands, and, in a lot of ways, no different from a king of those lands. He was a political figure as much, if not more, than a religious one.
Now, to the actual series of events...
Pope Alexander VI and his son, Cesare Borgia, we're an amotious duo. They managed to conquer lands in Northern Italy and place them under the control of the Papal States. When Alexander died in 1503, Cesare morphed those conqured lands into his own fiefdom and ruled them for about 5 minutes.
The College of Cardinals, full of French and Spanish anti-Borgia influence, chose Julius II to lead the Church (Pius III was chosen before him, but only lived for about 3 weeks after his election). Julius II was able to capture Cesare and strip him of his lands and titles.
Not sure what to do in the absence of Borgia rule, the lords of Cesare's lands declared their submission to the Republic of Venice.
This did not make the Pope happy and he ordered the return of these lands. Venice was disinclined to acquiesce to his request. And the Pope excommunicated every citizen of Venice and called upon all Christendom to aide in its destruction. France, Spain, and the Holy Roman Empire joined in... But France did most of the heavy lifting. They agreed that the lands would be divied up between them.
The Republic was unable to withstand the brutal onslaught so they agreed to a very Pope-friendly truce with Julius II.
France didn't get the memo and kept on conquering, eventually adding more lands to their Milanese holdings than were originally agreed upon.
The Pope didn't like that either. He was wary of such heavy French influence on Italy and saught to drive them out. The Venetians felt the same way, so the two sides high-fived and started an alliance. They pushed the French back to France.
Two key deaths lead to the French re-invasion. First, Julius II: his sucessor, Leo X, was much more religiously centered than politically or militarily. Second, King Luis XII: his successor, Francis I, was named the Duke of Milan as a part of his coronation. Because of this, Francis wanted Milan back under French control. So he went to Italy to get it.
Leo X's overall disinterest in military matters made it relatively easy for the French advance. Eventually the Papal forces either deserted or lost the will to keep fighting. France and Spain signed a treaty that recognized French rule in Milan and Spanish rule in Naples. The Pope recognized French rule in Milan also, as long as the French didn't interfere with the the Pope's current military operation in Urbino.
Source: https://en.m.wikipedia.org/wiki/War_of_the_League_of_Cambrai
Edit: source: Julius II: Warrior Pope by Christine Shaw
History of Venice by John Norwich