How is cross validation used to prune a decision tree As I understand it one can use cross validation to help find the optimal pruning of a classification or regression tree, for example, implemented here in Matlab. 

I do not understand the following about this process. Since each cross validation fold has random data, it may be that the trees fit on each data set may be different and have differing depths. How can one find the best pruning level over all such trees then?
I don't know how this is implemented in matlab. I know that some packages use cross validation to decide whether to grow the tree or not. Quite simply, they decide whether to grow based on that evaluation.

(Notice what a lot of packages call pruning is: during training, they mark branches with some score criterium and then remove if the user wants afterwards.)

Personally, I use sklearn which does not have this feature. So, I just do a grid search for several values of max_depth and use whatever maximizes accuracy or whatever score I want.