When calling the MakeFeatureLayer function in a python script, a lock file is created that may persist even after the script finishes. To remove the lock file, just call arcpy.Delete_management(layer) before the script terminates.
This forum post provided the answer to this problem.