Unless you had a written employment contract which prevented your termination for this reason, it was legal. Without an employment contract, you were an "employee at will": an employee at will has no rights in or two a job and may be terminated at any time, for any reason whatsoever, including a 17-year conviction.