The moral of the poem, 'Inchcape rock' is:
'As you sow, so shall you reap'.
Ralph, the pirate, went on an adventure on the sea with his sailors. He was brave to take the risk of cutting off the bell from the Inchcape rock. The motive for his wicked deed was jealousy. He could not accept the jealousy of the good abbot and tried to spoil his fame and reputation by cutting off the warning bell.
Since the punishment follows the crime, the poem ends with sir Ralph being punished for his evil deed. When palph was returning home with the loot he had plundered, his ship was sailing towards the scotland shore.
All of a sudden the ship struck the inchape rock. The pirate ship sank with sir ralph, who tore his hair and crushed himself.All happened because they already cut off the warning bell, i.e, the inchcape bell.
Again the moral: He who digs a pit for others, falls into it.
hope this helps.. :)