The first carbonated drinks were marketed as health tonics, so a pharmacist would be the natural person to sell them and/or acquire the equipment and manufacture them for sale.
PDF on origins of carbonated beverages
I'm afraid I don't know about ice cream.
I'm currently reading Karen Foy's Life in the Victorian Kitchen and she says that in the UK, at least, ice cream was first sold by street vendors, and we've never really had a tradition of pharmacies selling ice cream.
So I went digging around the interwebs, and various places suggest that ice cream was an addition to the pharmacy soda fountain when the latter became more popular during prohibition. So the soda was already in the pharmacy out of tradition from the days of carbonated health tonics, and suddenly the soda fountain was much more popular because people still wanted to drink and socialise somewhere but all the bars were closed. Owners will have been looking for more things they could sell to this renewed audience and the audience would have wanted some interesting drinks: ice cream and ice cream-based drinks provided this.
To be fair though, it's not my area and this is mostly from the research of this historical fiction writer.