ffmpeg asks before it replaces an existing output file. In a script there is nobody to answer, so you have to choose: -y to overwrite or -n to never overwrite.
for f in *.mkv; do
ffmpeg -n -i "$f" -c copy "${f%.mkv}.mp4"
done
With -n, ffmpeg checks the output name first. If the file is there, it prints “File ‘name’ already exists. Exiting.” and moves on. That makes a batch job safe to run again after it was interrupted: finished files are left alone and only the missing ones are made.
I prefer -n over -y for anything that writes to a folder with originals in it. A typo in an output name with -y can replace a file you wanted to keep, without a single question.
There’s a gap though. A half-written file from an interrupted run also counts as “exists”, so -n skips it and you keep the broken one. Delete the last file the loop was working on before you start again, or write to a temporary name and rename it when ffmpeg is done. Also check your script logic separately: ffmpeg 9 exits with status 0 when it skips, so you can’t use the exit code to tell “skipped” from “done”.
Further reading: ffmpeg documentation