Not quite.
pairs works by getting the indexed values, then the key/value pairs. It will get the first value from the table, and from then on it will get the next value in the table by using the value it currently has, this means that when you nil that value it cannot get the next, causing the error. This cannot be solved by simply saving the index of the current one you're on, because there will be the same problem, it cannot use that key/index to be able to get the next value, the only way that you could get it to work is if you were to save the key for the next entry before nil'ing the current one, however this is essentially you writing your own iterative loop.
The code I suggested was the easiest way to do it if you're dealing with a key/value table, however if you're using just an indexed table (which I just noticed that I think you are) the easiest way to fix this problem is to do the following
for i = 1, #locked do
if locked[i] == file then
table.remove(locked, i)
end
end
This will work as the loop increments the number, without worrying about the table…
Also as a slight side note, you should `break` the loop when you have removed the entry, unless you plan on having multiple entries that are the same value, in which case the above loop would have problems if the value you're removing is directly after one another, as the next one takes it's place, and then you miss it because you move on…….. this may be a little confusing, but I doubt that you're actually needing to do this, so use `break` after removing the value so the loop doesn't keep running because you've already found and removed the value.