Display latest 5 posts on homepage

The issue is with your $limit var, you can’t set a default value like that because WordPress overwrites it with an empty value. Check out the Shortcode API for the correct way to pass and set shortcode attributes.

function custom_prev_posts( $atts ){
    extract( shortcode_atts( array(
        'limit' => 5
    ), $atts ) );
    // the rest of your code, $limit now works correctly
}

You can also now set a custom limit by adding limit to your shortcode: [last5 limit=10] Though last5 is an odd name for a shortcode that can display numbers of posts other than 5 🙂

Also, for future reference, enable debugging so you can see errors your code is generating.