Mattis is a civilian. He retired in 2013.
The law is that the Secretary of Defense can’t have been active-duty military in the last 7 years. Mattis got a waiver for this- as did George Marshall in 1950 (who was legally active-duty military the whole time, as five-star generals never retire, though he’d effectively retired in 1945). On the other hand, when Congress voted to let Marshall be confirmed, they said “please don’t do this again”…