Here "hearts" is a metonym for the person's thoughts or inner person. The phrase "written in their hearts" is a metaphor for knowing something in their mind. You can translate this in an active form. AT: "that God has written on their hearts what the law requires them to do" or "that they know the actions that God wants them to do according to his law" (See: [[rc://en/ta/man/translate/figs-metonomy]] and [[rc://en/ta/man/translate/figs-metaphor]] and [[rc://en/ta/man/translate/figs-activepassive]])
Here "bears witness" refers to the knowledge they gain from the law that God has written in their hearts. AT: "tells them if they are disobeying or obeying God's law" (See: [[rc://en/ta/man/translate/figs-idiom]])