Sanskrit contrasted three sibilants, two of which most probably were [ɕ] and [ʂ] (or [ʃ]).
The former was an outcome of an Proto-Indo-Iranian affricate that developed from PIE voiceless palatalised velar stop whilst the latter had its roots in PIE /*s/.
Again here comes the matter of the exact phonetical nature of the second, non-palatal sound, retroflex [ʂ] or post-alveolar [ʃ]. In my view that doesn't matter so much, since Sanskrit didn't contrast all four places of articulation within sibilants (that is dental, post-alveolar, palatal and retroflex). The situation in Sanskrit would be similar to the one in Polish, described by Arsen before. Both [ʂ] and [ʃ] would be allophones of a phoneme that doesn't have to be specifically retroflex or specifically post-alveolar, it just has to contrast with the other two sibilants. In the light of that, it is safe to say that indeed ɕ contrast with ʃ.