C# List items magically disappearing

Today I encountered a weird bug. For some reason, on my end, a list is getting changed without my intervention.

I got a list of vectors, add components to the corresponding gameobjects, remove the corresponding vector from a list I passed as a parameter and enumerate through the rest of the vectors.
Enumeration happens in one MonoBehaviour, and removal in another. During enumeration via foreach list count stays sometimes the same, sometimes not, which throws an error in regards to foreach, regardless of that, the number of objects is reduced by one each time. The same happens when using for loops.

Could you explain why this could happen? I even tried to use a third component with only a getter and init method, but the same thing happens there too. I am confused. I thought lists retain their elements when being called.

It doesn’t sound like magic; you say you are removing one item each time.
If you have two separate scripts- one counting, one removing, the scripts are not guaranteed to execute in the same order, unless you tell them to.
But you don’t need one more component, you need one fewer.
You should do both the counting and the removing in the same script, in the same function, in consecutive lines in the same for loop.
If you do that, your problem will go away.