I personally wouldn’t while it’s under warranty but it’s up to you.
In the US the consumer is protected against this kind of stuff. You can definitely use non-mazda branded oil filters. The dealers here are terrible, but I have never had any issue as long as you document the oil changes. Point being, using a non-oem branded filter should be one of the last things to worry about when entering a Mazda dealership... hahaha.
In regards to the K&N filter. It is a re-branded Mobil 1 filter with a nut on the bottom for easier removal. If you compare the filter elements in the store, they are identical down to the numbers printed on them. The K&N from what I recall was about $1 more expensive. Please keep in mind that what the dealer will sell you in the US is not actually a Mazda branded filter. They sell "Mazda Value" branded products and they are of much lower quality than an OE filter you can buy online/amazon. Buyer beware.
Edit:
Just an FYI. The OE filter is made by Tokyo Roki Co. LTD and is a very good quality product. The part number is: PE01 14 302A
The cheapo stuff they are selling at the parts desk has the part number PE01 14 302A-MV. I attached photos so you can see the difference between the two. I didn't take a photo of the internal filtering element, so you can not see the internal differences. But just take a look at how much better the OE seal is (round) vs the MV (flat and not even).