Assuming Linux, there are a few ways to flatten a pdf from the command line while preserving the form contents, for example using cups-pdf, pdf2ps followed by ps2pdf, or pdftocairo. From these, pdftocairo is both easy to use and preserves the form mark-up, so I'll use it in the example below.
In order to automate the conversion, \DeclareGraphicsRule from the graphicx package can be used. The pdfpages package uses \includegraphics internally, so settings and options for \includegraphics also apply to pdfpages. The \DeclareGraphicsRule macro defines an external command to be run for the specified type of file, where the output is expected to be named filename-originalextension-converted-to.newextension. When converting from pdf to pdf this would be, e.g., test-pdf-converted-to.pdf.
Example document with form:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\TextField[width=4cm]{First name:}
\vspace{1mm}
\TextField[width=4cm]{Last name:}
\end{Form}
\end{document}
This document can be opened with Evince for example, filled in, and saved using Save as... in the Evince menu.
Assuming the file is saved as filledform.pdf the following code can be used to include this pdf in a new document. Note that the external command requires --shell-escape as a compiler flag (e.g., pdflatex --shell-escape myfile.tex).
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\DeclareGraphicsRule{.pdf}{pdf}{.pdf}{`pdftocairo -pdf #1 `basename #1 .pdf`-pdf-converted-to.pdf}
\includepdf[frame,scale=0.65,pages=1,pagecommand={PDF form converted with \texttt{pdftocairo}:}]{filledform.pdf}
\end{document}
Result:

Note that this approach will convert every included pdf file with pdftocairo. To perform the actual check mentioned in your question (i.e., flatten a file only if there is a pdf form), then you can use a test in a small shell script and call this script as external command in the graphics rule. The test itself can be performed, e.g., by pdfinfo (from Poppler), which outputs a number of properties of the file. If there is a form, pdfinfo will output Form: AcroForm or similar, otherwise the output will be Form: none. You can grep for this line and call pdftocairo for files with a form and cp otherwise.
Code (checkform.sh):
#!/usr/bin/env bash
if pdfinfo $1|grep -qE "Form: +none"; then
cp $1 `basename $1 .pdf`-pdf-converted-to.pdf
else
pdftocairo -pdf $1 `basename $1 .pdf`-pdf-converted-to.pdf
fi
combined with
\DeclareGraphicsRule{.pdf}{pdf}{.pdf}{`./checkform.sh #1}
in your document.