A man who brought a hammer to hospital in case he was “attacked by Muslims” is an ex-soldier who served two tours of Afghanistan.