Is 了 optional when a time word is present?
I think Chinese textbooks should start their 了 sections with this:


了 is not about time.
了 is not about tense.
Goto 1.


You are only concerned with 了 as an the aspect marker, aka completed action 了, or perfect aspect 了, so:

"昨天去商店" and "昨天去了商店" are both valid verb phrases. The second one explicitly states that the action was completed, whereas the first one does not.

As other posters have mentioned, "我昨天去商店" isn't wrong, but it is incomplete as a sentence because it leaves that verb phrase hanging. It feels like "Yesterday I went to the shop and..." in English. It needs to carry on with more information, e.g. "我昨天去商店的时候发现鸡蛋都卖完了".

"我昨天去了商店" is a complete sentence.

It might be easiest to look at examples to get a better sense of this:

我们昨天卖了十个。 -> "We sold ten yesterday."

到了红绿灯，往左拐。 -> "When you get to the traffic lights, turn left."

你买了东西以后可以去银行取点现金吗？ -> "After you've bought the things could you go to the bank and get some cash out?" (notice this in the future, the action hasn't happened yet, but still uses 了)

My point is that 了 is not about tense or time. It's about whether an action is complete in the time frame we're talking about.

I think that this is the sort of issue that can't be resolved by reading textbooks or explanations online. It's got to be done through long-term exposure and practice, in my view.