Similar idea, I use post order though. Btw, the return value type int[] make our code messy. So I ask help for lambda. Thanks for sharing!

public int[] findMode(TreeNode root) {
Map<Integer,Integer> freq = new HashMap<>();
int max = dfs(root, freq);
return freq.entrySet().stream().
filter(e -> e.getValue() == max).
mapToInt(e -> e.getKey()).toArray();
}
private int dfs(TreeNode root, Map<Integer,Integer> freq) {
if (root == null) return 0;
int l = dfs(root.left, freq);
int r = dfs(root.right, freq);
freq.put(root.val, freq.getOrDefault(root.val, 0) + 1);
return Math.max(freq.get(root.val), Math.max(l, r));
}