Is there a rule where s is pronounced s or sh?
st-, sp- at the beginning of a syllable are pronounced scht-, schp-, respectively, in native German words.
For example, Spitze, Stange.
In foreign loanwords, it depends a bit on how thoroughly nativised they are; Stil "style" is pronounced with scht-, but Respekt is usually with sp, not schp.
In words such as Statistik, the syllabificiation is sta.tis.tik, so the first st is pronounced scht but the second one is not, because the -s and the t- belong to different syllables. Similarly with ges.tern.
On the other hand, Gestirn (a poetic word for Stern = star) has scht since that is ge.stirn because of how that word is derived.
So you can't always tell just from looking at a word whether an sp or st in the middle of a word will be schp, scht or sp, st.
But it's probably good rule of thumb that in general, word-medial ones will belong to separate syllables and will thus not have the sch sound.
And then there are some people who pronounce almost everything as "s", mostly old people.
In German you say about them: "sie stolpern über den spitzen Stein". Most people would pronounce it as "sie s(h)tolpern über den s(h)pitzen S(h)tein", but when mocking someone who doesn't, you pronounce these three words as if they were written with a double s in the beginning.