It seems as though the piano and violin are the two primary instruments of 'classical' music, being featured in more concertos and being regularly included in small sets. What caused the focus on these two instruments?

by spkr4thedead51
RedViolinist42

The question itself is problematic in the generalization behind the term "classical"; very roughly speaking, the violin becomes relevant to music history in the late 16th century, while the piano arrives on the scene in the early 18th century.

During the 18th century, basso continuo defined accompanimental practice (at least outside of lute intabulations), meaning that a treble melody was typically supported by a bass line with numbered figures that suggested the improvisation of additional chord tones. Continuo instrumentation typically consisted of sustained instruments (i.e. the viola da gamba) alongside chordal instruments (the harpsichord, the theorbo, etc.). Treble instruments, on the other hand, consisted of a wide variety of instruments, which more and more came to include the violin.

The tastes of the 18th century shifted a great deal, displacing many older instruments. In the place of violas da gamba, the louder violin family of instruments (that being the violin, viola, and cello) rose to lasting prominence, though not so much that I would claim that the violin was that much more dominant than other instruments. Similarly, the fortepiano, the precursor of the piano which was invented around 1700, eventually succeeded the harpsichord in both soloistic and accompanimental roles.

The displacement of Baroque instruments has been studied in depth by music historians, yet the reason for the rise of more modern instruments such as the violin is slightly more esoteric. The work of Willem Kroesbergen and Jed Wentz, however, documents an aesthetic shift away from the Baroque sensitivity to delicate overtones towards stronger sounds and dynamic contrasts in the 18th century, with specific reference to the popularity of violins, trumpets, and organs. In the same article, they suggest that the harpsichord fell behind the fortepiano because, whereas the harpsichord had a relatively thin dynamic range, the fortepiano boasted a wider potential for dynamic expression.

References:

Schulenberg, David. Music of the Baroque. New York: Oxford University Press, 2001.

Rice, John. Music in the Eighteenth Century. New York: Norton and Company, Inc., 2013.

Kroesbergen, Willem, and Jed Wentz. "Sonority in the 18th Century, un poco piu forte?" Early Music, Vol. 22, No. 3 (Aug., 1994): 482-495.

EDIT: Some clarifications

Pit-trout

Not a historian, but as a musician, I'd pretty confidently assume it's because they’re the most versatile/capable at providing both harmony and melody on their own, and a range of different musical textures. A clarinet or horn is lovely in a group, but you can't do nearly as much with them on their own compared to what you can do with a violin or a keyboard instrument.

This isn't just a classical-music thing: you see it in folk, pop, and non-Western classical traditions too, that the most widely-used instruments (fiddle, guitar, banjo, piano, zither, pipes, accordions…) are ones that can provide at least some harmony on their own (for a second instrument/voice to play melody over), and ideally melody as well.

Going back to the classically case, though: the poano’s advantages are very clear. It's hugely versatile compared to non-keyboard instruments; significantly more so than earlier keyboard instruments like the harpsichord; and much cheaper/simpler than organs (its only real rival for capability), so is much more widely played/owned than them.

The violin is less of an obvious standout. Other modern string instruments also have great range and versatility — the cello maybe as much as the violin or even more. But in group settings, the dynamic favours focusing on the violin: one typically wants more high instruments than bass instruments for good balance/texture, and also, the melody most naturally sits in a high or mid-high part. (Again, these points aren't specific to classical music.) So that pushes to having more violins than cellos, and focusing on them as lead/melody instruments more often.