As a practical matter, I wouldn't recommend trying to analyze the grammar of "something the matter" in terms of "the matter" being a noun phrase. It looks like one, but I don't know of any way in which it behaves like one in this context. I also don't know of any useful way to explain the grammar with the concept of ellipsis.
Idiomatically, "the matter" can be used the same way as an adjective
Rather, I would recommend treating "the matter" in this expression as an indivisible idiomatic unit. It is synonymous with and can be replaced with the postpositive adjective "wrong":
There was nothing the matter with it when I lent it to him. = There was nothing wrong with it...
She had something the matter with her back. = She had something wrong with her back.
There's something the matter with my eyes. = There's something wrong with my eyes.
Collins COBUILD English Usage (accessible through The Free Dictionary by Farlex) gives the same explanation of how to use "the matter":
You use the matter in the same way as an adjective like wrong. For example, instead of saying 'Is something wrong?' you can say 'Is something the matter?'
(© HarperCollins Publishers 1992, 2004, 2011, 2012)
Some other material on the web I've found that brings up this topic:
How this usage developed
Unfortunately, I haven't been able to find any detailed account of how "the matter" came to be used this way.
Reinterpretation of sentences starting with "what is the matter (with X)?"
The Oxford English Dictionary (OED) entry for matter seems to hint that "the matter" has been reanalyzed as an adjective based on its usage in sentences like "What is the matter (with X)?" Specifically, the OED says "In recent colloquial use (e.g. quot. 1925) sometimes interpreted as a predicative adjective in the sense ‘wrong, amiss’."
This reinterpretation seems to have been possible because sentences of the form "What is [X]?" are syntactically ambiguous: the subject can be either "What" or "[X]", and when "What" is the subject, "[X]" can be either a noun phrase or an adjective (or it could even be something else, like a prepositional phrase, but that's not relevant to your question).
There is evidence that "the matter" has sometimes been used as a subject noun phrase in sentences like this. For example, the word order in the following OED citation implies that "the matter" is the subject of the clause:
1560 J. Daus tr. J. Sleidane Commentaries f. cccxxiiiv No man knew what the matter was.
So we can see that there has been some variability in the usage of this expression. In fact, it seems that we still see variation in the structure of sentences like this today: some speakers might say "I didn't know what the matter was with him", while others might say "I didn't know what was the matter with him". "The matter" is used like the adjective "wrong" in the second sentence, but not in the first. Here are some online posts that discuss the variability in usage in these kinds of sentences:
My assumption would be that constructions like "nothing the matter with", "something the matter with", etc. are based on that reinterpretation of "the matter" as an adjective (but one that can only be used predicatively or postpositively, not before a noun).
A possible comparison: "fun" (n.) > "fun" (adj.)
A phenomenon that seems somewhat similar to me is the development of the adjective fun from reinterpretation of sentences containing the noun fun without a definite article (such as "It was fun").
A similar-looking construction that might not be related
I have no idea whether the "something the matter (with)" construction is actually related to the following constructions, but on a superficial level, I think they look similar.
You can find "the" after "something" in the expression "something the size of...", and in some similar expressions that are described in more detail in the question here: It's the size of a brick; What size shirt/shoes do you take?; I have a daughter your age
As the title of the question demonstrates, "the size of..." can be used not only after indefinite pronouns, but also after regular nouns.
Sadly, that question didn't get any answer from a linguist, but you can see my attempt at analyzing, or at least discussing, that construction on the linked page.