Paul wrote 1 Timothy and Titus during the time of freedom between his first and second imprisonments, not during a prison imprisonment.
Watch the Teaching: Why Did God Choose Paul to Reach the Gentiles?