I find the base problem surprisingly complex:
Special case 1: 2 pirates
Whatever the leader proposes, nr2 votes against , the leader gets killed and nr2 happily leaves with all the gold.
Special case 2: 3 pirates
Due to case 1, the number 2 pirate does not want to become the leader since that gets him killed, thus the leader can assign all gold to himself
Otherwise: Assuming he has the gold, the leader will offer 1 gold to all pirates the next leader would ignore, and occasionally 2 to a pirate that would get 1
This does not completely work
Special case 3: with 6 pirates, it is unclear which pirate gets 2 the next round, but you need the loyalty of 1 of them; to be certain of their loyalty 3 should (probably) be paid.
A listing up to P=13:
{?,?} nr2 always votes against; leader gets killed
{G,0,0} nr2 supports leader or both will get killed -- so leader can take all gold
{G-2,0,1,1}
{G-3,0,1,(2),(2)} (1 times 2, leader's choice)
{G-6,0,1,2,(3),(3)} (1 times 3)
{G-6,0,1,2,3,0,0}
{G-5,0,1,2,0,0,1,1}
{G-5,0,1,(2),0,1,1,(2),(2)} (1 times 2)
{G-8,0,1,2,0,1,2,2,0,0}
{G-6,0,1,(2),0,1,(2),0,0,1,1} (1 times 2)
{G-8,0,1,(2),0,1,(2),0,1,1,(2),(2)} (2 times 2)
{G-9,0,1,(2),0,1,(2),0,1,(2),(2),0,0} (3 times 2)
Special category: What if a leader does not have enough gold?
Normally that would mean getting killed, but with a small shortage this does not necessarily happen:
With 5 pirates and 1 gold the second in command would also get killed the next round - so will support the leader even with 0 gold offered!
Thus the leader can offer the single gold to nr 4 or 5.
With 5 pirates and 2 gold the second in command would get no gold (or get killed) the next round - so will support the leader even with 1 gold offered!
Thus the leader can offer 1 gold to nr2 and nr3.
Similar things can happen with larger numbers
Addition
Assuming pirates can be counted on to use probability the solution becomes a bit cleaner:
If there is plenty of gold:
Number 2 wants to be captain desperately and only supports the captain for a large sum; thus is a lost cause and gets nothing.
Number 3 does not want to become nr2 for above reason; will support the captain for 1 gold.
The lower ranks are greedy they know they can get at least 1 on average and with their gambling habits understand probabilities; enough of them need to be paid at least 2.
If gold is scarce:
The lower ranks know they get less than 1 on average if the captain dies; enough of them need to be paid for their vote but 1 is enough.
The higher ranks will form blocks, they will give free support if the captain getting killed will also get them killed.
The first block will be 2 pirates (with 1 free vote from nr2).
The next block will be 4 additional pirates (with 3 free votes from nr2..nr4). etc.
The transition:
odd P and P-2 gold
In this case your number 2 will get no gold if the captain dies.
The captain ,nr2 and nr3 can all get 1 gold and be happy while 1 lower rank need to be paid 2 to be happy. This is the minority of them, allowing the switch to the scarce gold scenario!
odd P and P-1 gold
In this case your number 2 will get 1 gold if the captain dies
The captain and nr3 can both get 1 gold and be happy, while nr2 and the lower ranks need to be paid 2 to be happy. This is the minority of them, allowing the switch to the scarce gold scenario!
example: 8 Gold
P
2 captain gets killed
3 8@0 @: gets paid 0 but supports
4 6011
5 501?? ?: 1 gets paid 2
6 301??? ?: 2 get paid 2
7 301???? ?: 2 get paid 2
8 101????? ?: 3 get paid 2
9 1?1?????? ?: 3 get paid 2; the minority!
10 30#0###### #: 5 get paid 1
11 30(5/9) (5/9): 5 of last 9 get paid 1
12 20(6/10)
13 20(6/11)
14 10(7/12)
15 10(7/13)
16 00(8/14)
17 0(8/16)
18 captain gets killed
19 0@(8/17) @: gets paid 0 but supports
20 captain gets killed
21 captain gets killed
22 captain gets killed
23 0@@@(8/19) @: gets paid 0 but supports