It is only after the first ballot that the delegates can vote their conscience. Only we won't have a second ballot because Trump will get the necessary majority on the first ballot.
The delegates can vote however they want. (They won’t, but they can.) They can be subject to punishment under state law for not voting as directed by state law, but that’s after the fact - after the vote has taken place.
State laws cannot be enforced at a national political party’s convention and there is no federal law governing how delegates must vote. The courts have ruled repeatedly in favor of political parties’ right to govern themselves. They have freedom association.