Goes the same old rule.
"ask what the matter is" is correct. "ask what is the matter" is incorrect, however, frequently heard in colloquial speech. Hands down. The adverbial (prep + noun) does not matter, put it wherever you feel like. But most common to say "ask what the matter is with you".
The subject is "matter", same as in "what is your name", "(your) name" being the subject.
This confuses many native speakers, the reason why "ask what's the matter" sounds natural is that, simply that, people say it often enough. It almost becomes a "fixed" idiom, so the rule is you don't make change to an idiom. There is only this one exception: Which. You could say "ask which is the answer", which'd be taken as correct, but still, "ask which the answer is" is the correct one in strict grammar.
And do tell the difference between "what's good/wrong" and "what's your name/an apple", as Mr. Brown suggested yet failed to clarify.