Considering the times that Locke wrote his “Two Treatises of Government” in. Cromwell’s revolution was over and the Crown had been reestablished. His writing bordered on high treason. But the examples of the American Indian was to overwhelming for him to deny. And his great analytical mind brought forth this great piece of philosophy.
Yes, the works of Machiavelli and Algernon Sidney were posthumously published, and Locke tried to deny his authorship of Two Treatises until it was clear that James II or his son wouldn’t attempt to retake the British Crown.
IIRC, Two Treatises was the last sanctioned book burning at Christ’s Church.