For activity selection, you sort by end time. For merging, you sort by start time. Why the difference?
Sorting by end time works when you want to maximize count. The activity that ends earliest leaves the most room for others. It is a greedy choice that provably leads to optimal solutions.
Sorting by start time works when you need to process intervals in order. For merging, you must see each interval as it begins to decide if it overlaps with the current group. The right sort order depends on your goal. Maximum count? End time. Process in order? Start time. This distinction separates correct greedy solutions from wrong ones.