To have tried to prevent something happening but done so too late to prevent damage being done.
John Gower’s poem Confessio Amantis published in 1390 and it may be that the proverb was in use in everyday language for some time before that: For whan the grete Stiede Is stole, thanne he taketh hiede, And makth the stable dore fast.