Are you asking about how an online version of the game is programmed? Or about the basic rules of when cards are dealt in a stack?
If it's the latter, then each type of Solitaire game has rules that describe how cards should be dealt. In the "standard" solitaire game, there are 5 stacks of cards. In the first stack, a card is simply placed face up, with cards being placed face down in all other stacks. This dealing pattern repeats, with no cards being dealt on piles that have a face up card, where the first pile dealt to is given a face up card, and all others are given a face down card. Other solitaire games have other sets of dealing rules.
If you are asking about how a computer program knows how to "deal cards," that is a harder question, since every program approaches the problem a little differently.