It sounds a bit dubious that we could run out of fundamental discoveries as our technology advanced. If anything, we should be discovering things at an accelerated rate when our technology allowed ever more outlandish experiments to be carried out.
Well, no matter what instruments and technology one has, the electromagnetic waves, for example, will have the same properties and will be described by the same equations.
If, by the 22nd century, humanity/the Federation figured out the fundamental physical laws of the universe - the theory of everything, how the quantum level and relativity fit together - than all that's left to discover are details - exotic phenomena, etc.
The bulk of the research will focus on finding technology that makes beter use of the physical laws of the universe - by this point thoroughly known.
And in this area, as exemplified by the tremendous increase in warp velocity, nothing stagnated. Quite the contrary.
The technology in the 24 century resembled the one from the 22nd century simply because it used the same laws of physics and principles.
It's of course possible that discoveries would come to a grinding halt in the 22nd century, when humans made contact with older and wiser species. They'd have so many answers for questions we didn't even yet have the intelligence to ask that our science might collapse out of sheer anguish. And possibly the formation of the Federation would do the same to the sciences of most of the other species, too.
Perhaps that is indeed what has happened in Star Trek? The Federation has been divided into those dispirited by the superior knowledge of others, those rendered complacent by their superior knowledge, and a teeny weeny handful of people who still dare postulate that they don't know everything. Thus, our heroes teeter on the verge of major breakthroughs such as the one relating spacetime and thought, but they dare not take the required steps because in the 24th century, only charlatans research things they don't already know everything about. And besides, dabbling in such things is dangerous...
The 2300s could well be the new Middle Ages in that respect.
Timo Saloniemi
Yes - in a few episodes - from TNG and Voyager - it is implied that, beyond the subatomic level, at the most fundamental, the trekverse is composed out of matter, energy and thought, united.
However, the ability of corporeal beings to discover this level by physucal means is doubtful.
Corporeal species such as the Voth (millions of years of technological development) or the borg (who assimilated thousands of advanced civilizations) were not aware/could not use this level of the universe.
Apparently, corporeal beings could discover and learn to use this level of existence only by PSI means and, once they mastered it, they "ascended" - much like Wesley or Kes.