In Sherlock season 4, episode 2: "The Lying Detective", why does Smith ask the nurse and the guy in the mortuary as to how long they've worked at the hospital? What does he calculate with their duration at the hospital?
He usually asks people's employment longevity when they have criticised or questioned something he has done or when they refuse to immediately do something he has requested.
The way he asks often hints at some sort of subtle threat to their future employment (he seems to be insinuating that it would be a pity if that turned out to be their full longevity at the hospital.)
So the reason he asks is (implicitly) a threat to enforce their understanding that he has power over their future employment and it would be better if they always did as he asked and never questioned him.
As each occurrence happened when a member of staff was trying to restrain him or not bend to his will, I believe it was simply his not-so-subtle way of reminding them that he had the power to remove them from their jobs at his whim, should they question his actions again:
With the nurse:
Um, Mr Smith, I'm just wondering, maybe this isn't a suitable subject for the children.
Nurse Cornish, how long have you been with us now?
Seven years. OK.
And in the morgue:
Mr Smith, we're actually in the middle of something.
Saheed, isn't it?
How long have you been working here now?
Four years. Well, that's a long time, isn't it? Four years!
In many employment settings, seemingly more often in unionized environments, seniority determines ranking within classes - so someone who has been working somewhere longer outranks someone who has been working there less time. Calling attention to differences in seniority provides a reminder of differences in status, and may increase the probability of deference to the more senior person's opinion.