In Chinese grammar, words as 什么 are commonly known as interrogative substitutes, they substitute the word that should be found in the answer.
Therefore, they have inherent interrogative semantics, and don't require interrogative particles at the end of the sentence.
For example:
你在吃什么?What are you eating?
我在吃麻婆豆腐 I'm eating "mapo" tofu.
As you can see, the interrogative substitute and the noun phrase that answers the question are in the same place, and there's no 吗。
When you do place an interrogative particle at the end of the sentence, the interrogative substitute plays the role of an indefinite pronoun. We can summarize this in the following table:
什么,什么东西 -- what? -- anything -- (thing)
哪里,什么地方 -- where?-- anywhere -- (place)
谁,什么人 -- who? -- anyone -- (person)
A couple examples more:
你包里有什么东西?What's in your bag?
你包里有什么东西吗?Is there anything in your bag?
这个周末你准备去什么地方?Where do you plan to go this weekend?
这个周末你准备去什么地方吗? Do you plan to go anywhere this weekend?
谁认识他?Who knows him?
谁认识他吗?Does anyone know him?
So your sentence:
你有什么事吗 (interrogative + particle = indefinite) do you have anything? (= is there something wrong?)
你有什么事 (interrogative) what do you have? (= what's the matter)
At the end of the day, in this particular example both sentences can actually be translated as "what's the matter", since in Chinese 有事 has an idiomatic meaning, but in general:
interrogative substitute + 吗 = indefinite pronoun.