Sometimes things happen. I think it is unfortunate that they did not disclose prior sale, but I do not think the law requires that- That is a problem.
A car previously purchased and returned is not "new" but used.
Regarding your repair the dealer will have to handle that and if the car is properly repaired and works as it should you should be ok.- This is a big if.
Ask them for repair history on vehicle since it was previously owned.