Here is a solution:
\documentclass{article}
\usepackage{pdfpages}
\usepackage{xparse}
\usepackage{l3graphics}
\ExplSyntaxOn
\NewDocumentCommand\settotalpagestomacro{mm}{\graphics_get_pagecount:nN {#1}#2}
\ExplSyntaxOff
\usepackage{xfp}
\NewDocumentCommand\includelastpages{O{1}m}{%
\bgroup%
\settotalpagestomacro{#2}\lastpage%
\edef\prevlastpage{\fpeval{max(1,\lastpage-#1+1)}}%
\includepdf[pages=\prevlastpage-\lastpage,fitpaper]{#2}%
\egroup%
}
\begin{document}
\includelastpages[2]{file1.pdf}
\includelastpages[4]{file2.pdf}
\end{document}
The \settotalpagestomacro uses recent version of l3graphics to get number of pages (see this answer Get number of pages of external PDF).
The fitpaper option adjusts the paper size to the one of the inserted document.
The \includelastpages macro includes the last pages from a PDF file. The optional argument defines the number of pages (default value: 1).