When the User Login section is enabled for the header the user who logs in or out is redirected to some random post.
wp_logout_url( get_permalink() ) and
wp_login_url( get_permalink() ) that is used in header.php does not work properly. From codex on
Note that when used outside The Loop on a posts page (index, archive, etc.) without the ID parameter, it will return the URL of the last post in The Loop, not the permalink for the current page.