How to create new content type and flushes rewrite rules without visiting the permalinks page?

Make sure you register the new post types before flushing! So call the function that registers them not only on init, but also in your activation/flush function.

See very first example here: https://codex.wordpress.org/Function_Reference/flush_rewrite_rules.