Assuming I've not missed something that's already possible, it appears that there is no way to lock comp markers via scripting. The only apparent way to do this inside After Effects is by right-clicking a comp marker and selecting 'Lock markers'.
Layer markers can be (un/)locked via scripting by invoking the relevant menu command ID, but it would be helpful to also have a method available for comp markers.
Alternatively, it would be helpful if invoking the command ID (2565) could toggle locking comp markers when no layers are selected.