The actual meaning seems to be "If you cooperate with me when I need your help, I will cooperate with you when you need my help"
"Ancient proverbs" often originate from the Bible, and He that will not when he may, when he will he shall have nay does not seem to be an exception: it repeats the message of the Book of Jeremiah (written c. 525 - 500 BC) in which, the prophet Jeremiah repeatedly tells the people to worship "the one true god" because He is the only god that can help them, and if they do not listen to God, He will not help or listen to them:
From the New International Version
Jeremiah 11: They have returned to the sins of their ancestors, who refused to listen to my words. [...] 'I will bring on them a disaster they cannot escape. Although they cry out to me,* I will not listen to them.
This message is repeated in the Book of Proverbs (written c. 325BC) Chapter 1:
24: But since you refuse to listen when I call and no one pays attention when I stretch out my hand, [...] 28 Then they will call to me but I will not answer; they will look for me but will not find me, ...