A splitting theorem for capillary graphs under Ricci lower bounds