In Turner v. Safley, 482 U.S. 78 (1987), the U.S. Supreme Court held that a prisoner has a fundemental right to be married that can be restricted only for reasonable Penological reasons. Therefore, you should check with the prison authorities where your boyfriend is detained to know their procedure for allowing an inmate to be married. However, the fact that you marry your boyfriend does not by itself make him eligible for an immigration benefit. In addition to the main requirement that the marriage must be bona fide, your boyfriend must satisfy other requirements. You should consult with an attorney before taking this important step.
Question is really about weather jail will let you i to marry him, or if he can get out on bond. If so, there are forms that can be filed by you, but these forms, even if approved are only half the process. If he entered the US unlawfully chances are not good that he could sty in US to get green card. How long you know each other is a factor in weather USCIS approves the petition that you file for him to show a legit relationship.