Find these all the time & yes part of a locking mechanism & its my understanding they haven't changed since Roman times. We find them on most Roman Sites.Looks to be part of an iron tubular padlock:
View attachment 1874752
The above photo is from finds.org.uk and it has it listed as medieval period.
https://finds.org.uk/counties/findsrecordingguides/padlocks/