The declension of pies was more regular in the past. The Proto-Slavic nominative was *pьsъ, with ь being a so-called yer, an ultra short vowel. All yers disappeared later in Polish, but in positions, where their diappearace would have left a syllable without a vowel, the yers were lengthened to a full vowel instead. That's why *pьsъ became pies (vowel lengthened), but the form *pьsà became psa (vowel eliminated).
Well, kind of, but not exactly. The original word was *pьsà and the ь was a very short vowel. I'd say that it was as short as the /i/ in the American pronunciation of /directly/. It was in fact so short that at some point speakers failed to articulate it properly and later even omitted it entirely. However, if the same thing had happened to the nominative form, the modern Polish word for 'dog' would have been 'ps'. It's quite obvious why this form kept a vowel. And since ultra-short yer-vowels were already out of fashion, it became a regular mid-length vowel.